AlexGalays/abyssa-js

Add/remove States at after Router init

Closed this issue · 5 comments

I think an important feature would be able to add/remove the Router states in runtime after the router has been initialized. That would allow the self-contained components to construct States on the fly when they become available to the user (e.g. when they are lazy-loaded).

A real application example is a lazy-loading wizard (a dialog with steps). The application controller may not know all the wizard's States during the Router initialization because the wizard is not yet loaded.

One thing that annoys me a bit is that you can bookmark/copy-paste these lazy loaded states' urls.
What happens then if the user goes directly to it the next time? You would have to lazy load that state before router.init() and that means knowing what kind of url that lazy module uses. Thus, I don't see a benefit of lazy-loading the state over lazy-loading the code inside the state?

@sompylasar #20 is a different feature request and I still consider it valid. I like this feature request as well. As we grow, we may have several similar sites that each contain child applications shared in a single web domain. In place of globally defining all, it would be good to have the top level sites initially defined, but then we recognize when a top level site is accessed to register the child application states.

In short, allowing additional sites to be defined after init gives us a lot more flexibility to decentralize the definitions. The use case becomes more valid as you add applications across development teams.

@AlexGalays It would be enough to define an entry point State which will
perform the loading/initialization.

If one bookmarked a state which does not currently available in the app
(this btw may happen when the routes are statically defined e.g. a URL of a
deleted resource or a resource with access restrictions) then the app
should handle this by showing a message or moving to another state. If the
state is handled by a separate component, the component itself should
determine that the resource is not available.

Is that good enough?

More root states can be added after router.init():
d7162d1

Looks good at first sight.