Comments (7)
Hey @ianmstew!
I agree with you that Backbone's route sorting mechanism causes problems. Sorting routes into an array and comparing them one-by-one without any notion of sorting is a very limited approach to routing.
With that said, I don't think the solution is to continue to operate in that restricted environment, which is what is happening with the proposed insertX
API. I'd much rather rewrite the match routing algorithm.
I've been looking at Ember's implementation, which is pretty smart, I think, and would remove the need for that insert
API. I might write an adapter for it to be used by Backbone.History, then link it up to the base router somehow.
What's your use-case for route removal?
from backbone.base-router.
The issue would come from ranking regexps I'd think
from backbone.base-router.
@jmeas, nice! Preferring static -> dynamic -> star routes, as you pointed out Ember does, would allow a catch-all "star" route to be matched last without managing order.
Taking a step back, what if a collection of matched routes is returned, in the order they were registered? This is even more abstract, does even less than Backbone, Ember, or Express do for you, but leaves the route selection algorithm up to the developer. One could re-engineer any of the above routers or, more interesting, create a possible combination of them.
To answer your question, my only reasoning for route unregistering is logical completeness. If a module registers its own routes on instantiation, then unregistering those routes on destruction seems like a parallel. I cannot, however, think of a use case that would benefit from short-lived modules, and if there is any internal reliance upon ordering then this could get messy.
from backbone.base-router.
I've been thinking to use dependency based object storing, maybe in a linked list or something.
You could first load your app and then insert your module routes without having to worry where it will stored into.
from backbone.base-router.
@Anachron, can you elaborate?
from backbone.base-router.
@jmeas sure!
If you use a linked list or graph you can store your dependencies. Then when you load or unload modules you read the dependencies to insert the routes before or after the dependencies, depending on the definition. When you unload you will remove the node that has been linked to the unloading module.
All of this should be optional, of course.
from backbone.base-router.
Interesting @Anachron. I'm going to close this issue because I think it's beyond the scope of the router to fix Backbone's route resolution mechanism. I think such a change would get into overriding History. I'm also still not that big a fan of skirting around the issue by removing / inserting routes into the handlers array.
I'm planning a new system for routing that solves all of these problems, and more. Base Router is a good library to use in the meantime tho'.
from backbone.base-router.
Related Issues (14)
- Move route params off prototype HOT 1
- Use prototype constructor HOT 1
- Store regex at top of file
- Figure out what it takes to support earlier versions of Backbone HOT 2
- Support canceling routes on navigate HOT 3
- Parse array query params
- Update coverage script HOT 1
- Upgrade dependencies HOT 3
- Examples too simple HOT 2
- Any objections to bumping backbone version to 1.3.3?
- Add npm scripts
- Overwrite navigate function HOT 1
- Double use strict HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from backbone.base-router.