router
router copied to clipboard
Feature query: stateful routes (module + viewport)
I've got code for stateful routes, meaning that if you do this
{ route: 'dashboard', name: 'dashboard', viewPorts: { 'default': { moduleId: 'dashboard', stateful: true } } }
the same instance of the dashboard module will be presented in the default viewport everytime a stateful route specifies it after the initial time. The view/viewmodel will remain loaded even when navigating away to another route, meaning that state such as list sorting, entered values, positions on google maps etc will be the same when coming back to it. It also means that the viewmodel will be able to listen to and act upon events from the event manager, signals and so on.
So to clarify, this is not caching for views/viewmodels, it's stateful views/viewmodels that are never unloaded.
If this is of interest to anyone else and has any chance of being accepted into the router I could put together a PR.
Is this something you want in? @EisenbergEffect @bryanrsmith
I like it!
@jwx Isn't this solved by making your view model a app singleton?
https://gist.run/?id=f9ec79977fdc755e65fd8bc69aa5fb44
@EisenbergEffect see here
@davismj @EisenbergEffect Making the view model a singleton only preserves the view model state. State details not bound to the view model is lost, for example an unbound scroll position in a list or unbound position and zooming in a google map. Basically, this is completely cached views through show and hide.
Good info. I'll review again.
I'd like to pull this in out of the context of the optional and default view ports. This seems like a totally separate item.
I'd like to add in that making something singleton
is not always viable. Sometime the element used at the leaf - route may end up being a real element in another context, thus making them singleton will not allow this scenario. My use case is I have a complex editor as a route, but then in another route, I reuse the element in a dialog.
Don't like the seeming hackiness of it. Kinda shoehorning. you actually can achieve it with optional viewports now i think and a bit of css magic.
@Alexander-Taran See https://github.com/aurelia/router/pull/538.
@bigopon @jwx - any news on this or #538 ?