GithubHelp home page GithubHelp logo

Comments (7)

jamesplease avatar jamesplease commented on May 18, 2024

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.

megawac avatar megawac commented on May 18, 2024

The issue would come from ranking regexps I'd think

from backbone.base-router.

ianmstew avatar ianmstew commented on May 18, 2024

@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.

Anachron avatar Anachron commented on May 18, 2024

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.

jamesplease avatar jamesplease commented on May 18, 2024

@Anachron, can you elaborate?

from backbone.base-router.

Anachron avatar Anachron commented on May 18, 2024

@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.

jamesplease avatar jamesplease commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.