router icon indicating copy to clipboard operation
router copied to clipboard

Feature query: stateful routes (module + viewport)

Open jwx opened this issue 7 years ago • 10 comments

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.

jwx avatar Oct 14 '17 21:10 jwx

Is this something you want in? @EisenbergEffect @bryanrsmith

jwx avatar Oct 14 '17 21:10 jwx

I like it!

TonyLugg avatar Oct 14 '17 22:10 TonyLugg

@jwx Isn't this solved by making your view model a app singleton?

https://gist.run/?id=f9ec79977fdc755e65fd8bc69aa5fb44

davismj avatar Nov 12 '17 16:11 davismj

@EisenbergEffect see here

davismj avatar Dec 10 '17 19:12 davismj

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

jwx avatar Dec 10 '17 22:12 jwx

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.

davismj avatar Dec 11 '17 11:12 davismj

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.

bigopon avatar Dec 11 '17 11:12 bigopon

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 avatar Mar 22 '18 21:03 Alexander-Taran

@Alexander-Taran See https://github.com/aurelia/router/pull/538.

jwx avatar Mar 22 '18 21:03 jwx

@bigopon @jwx - any news on this or #538 ?

jfstephe avatar Mar 27 '20 10:03 jfstephe