-
-
Notifications
You must be signed in to change notification settings - Fork 115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
View and ViewModel caching option in router #173
Comments
+1 |
Agree. The navigation caching is a standard feature in most app framework. This should be a top priority for Aurelia team, quoting the aurelia mission to be "strongly focused on developer experience". |
It is planned. If you want, you can implement it now yourself. What you would need to do is create your own version of the router-view element that caches and re-uses view instances. We will build that in though. |
Sounds good. I'll prefer to wait then, while I still need more time to familiarize with other Aurelia concepts. It'll be great to see this implemented before beta though. Thanks! |
Thanks @jods4 for the update. Since the view caching is my primary concern, I'll be looking forward to it and give it a spin once it's available. Is it currently in progress? Any ETA yet? |
With respect to the view cache...no "official" work has been done yet. However, as part of some work for a customer, I built a floating window system on top of the router. So, when routes were re-visited it would use the existing view and view model (and simply bring the window to front) rather than re-create them. That work will help in implementing the router-view's caching implementation. There are a few other high priority issues that need to come first, but this is still planned and that bit of very specific work has some general code that will likely make implementing this much faster. |
Thanks for the insight @EisenbergEffect. No worries, just take your time to proceed with other higher priorities for now. It'll be great if the view cache can make its way sometime after the beta, or possibly before the RTM. |
Will some form of offline (aka web storage) technology be implemented? |
just loud thinking:
|
Any progress on this @EisenbergEffect ? I'm trying to build an "admin" style application. There's a main router on "app" linking to "login", "register" and "shell". "shell" in turn has a child router, with all the application's menu items in the sidebar (think WordPress's admin app). I'm desperately trying to find a way to reuse the Views and ViewModels inside the child router, its where the complexity and UX lies. I also attempted to eliminate the child router and use two view ports, but to be able to utilize this approach, I would need to only link to either the link on the "app"'s , or the "shell"s . Aurelia doesn't allow this, it seems I have to use both for each route. |
You can implement it yourself. There's no need to wait on us. The |
Ok, thanks will take a look at router-view and give it a go. |
Just to add my 5 cents on this topic I'd expect a similar behavior than in xaml PRISM framework. I like this way of handling views although I suspect it's no as easy in html as is in xaml to keep views alive in memory disconnected of the visual tree. |
a couple more cents to add 😄 @Alxandr gave me a solution a long time ago:
ping @EisenbergEffect |
@cmichaelgraham I think the issue here is not Resource pooling but View caching. At least I understood it differently. Notice how the OP wrote:
Currently the problem with back navigation in Aurelia is that there's no way to restore any state that is not bound to a singleton ViewModel. Binding all state is tedious and useless. Typical state that you would not bind but can expect to persist: scrollbar positions, active tab in a tabcontrol, maybe focus, etc. I see that your code uses the view url as pool name, which should make it unique and implies you will get back the same (
PS: that said, view pooling is an excellent tool to have at hand, esp. in virtualized lists... |
I'd just like to note that the resource-pool mentioned was done by me as a proof of concept. It has basically no features, and was just a test to see mainly if it could be done. [Edit] |
I should have mentioned that @Alxandr work was a Poc. Also @jods4 I appreciate your input. I may have misunderstood the original ask. i'm trying to figure out a clean way to make this globe from esri maintain its state when you navigate away and back. it definitely falls outside the normal view case... http://cmichaelgraham.github.io/skel-nav-esri4-vs-ts/index-release.html#/esri-globe |
@cmichaelgraham I don't know how you did it, but it seems to work ;) When I go back the globe is at the exact same position! I think using 3rd party plugins (e.g. jQuery plugins) that were wrapped into a custom attribute or custom element is the perfect example where you don't control the complete UI state and need a very special solution if you want to restore the view exactly as it was before. |
I need multiple instances of the same viewModel class to be active at the same time (I have a tree view on the left side of the screen and as I click the node in the treeview the right side is populated with data. Every node has it's own instance of viewModel) |
You would need to implement your own RouteLoader as well. It's another extensibility point. You can look at the default implementation. It's also in the templating-router repo. Once you implement your own, you would need to register it in the root DI container. |
Thank you. It works great. I really enjoy working with Aurelia.
but that method was never called. So I looked through the source code and found that this always overrides my strategy (in router, class BuildNavigationPlanStep)
Is there any way I could skip activate method on VM? My current solution is a bit of a hack.
|
You can always implement a simpel |
@EisenbergEffect In the same vein of what @rborosak asked, but opposite: |
Yes, 7use |
I have exactly the same question / need as @jods4. I've got a "users" route (list of users) and a "users/add" route (to add a user). If I add a user and navigate back to the list and then navigate to "users/add" again, the previous values are populated. I've added the Could this be as a result of the view being cached and its "bound" values are pulling through to the VM? Or is the VM (as well as the V) possibly cached in a way that I'm not aware of? I've played around with |
@stefan505 You have something else going wrong. If you navigate back and then you navigate to a new route, you will get new instances unless you changed something somewhere explicitly. I'm going to take a wild guess here.. are you trying to inject |
That sounnds like a bug. Please create an issue on the aurelia-polyfills repo and attach a zip containing the source for a simple reproduction on top of the nav skeleton. |
Opened aurelia/polyfills#17. No zip needed I think, since the bug triggers just adding |
I just want to say +1 on this feature request. I think this should be considered a "core" feature that should have been done a long while ago. I have been trying to make it myself and it is hard for someone not familiar with the internals of Aurelia. |
@Vaccano Just follow what @EisenbergEffect suggested. I'm a total JS noob and I got it working so I believe anyone can. |
@rborosak I would LOVE a code sample. I am am not doing too well on this one. |
Here is a link. That works for me, but as I said I'm a JS noob so it might not be the best solution :) https://gist.github.com/rborosak/dc505e32a672e60c061dccd048767a98 |
@rborosak Thank You! I will give it a look. |
@rborosak That was really good stuff! Thanks! Would you be willing to show where/how you plugged into the ViewFactory? |
Here it is, but I'm not sure if it works. I think there is some problem with showing invalid data (red square around invalid text boxes) with cached view so I'm not using view caching. I always create a new. Although I wasn't using the new version of aurelia validation. https://gist.github.com/rborosak/265ece1aee0628219af0566fb552d721 |
I'm also interested in this feature. In the mean time I'm developing hybrid mobile apps with ionic, but I plan to start with Aurelia as I think it's the best javascript framework . Ionic implements this feature out the box. From ionic docs:
|
@jesuslpm I implemented a navigation-view for that reason: Demo: |
@Scapal Great!! Thanks!! |
@EisenbergEffect - You mentioned this was coming with Aurelia Interface. But now that project is "dead". Is this feature dead too? I ask because getting something working here is not too hard, but getting it working well with the router is hard. And really is something I am supprised is not just "baked in". |
There's already work being done for this. There are two PRs being worked on by @jdanyow for this. |
@EisenbergEffect This new feature is in progress? #425 looks like in suspended. |
Jeremy just moved across the country and took a new job. So, that has slowed down his contributions while he's been making the transition. |
@jdanyow @EisenbergEffect I have been working on this in my code for days. It is a very hard problem to solve. The problem is that if you just cache the view that is the routed view you get issues with custom elements that you have composed on to the "parent" view. I have found a way to iterate down the tree of custom elements and custom attributes. But there is a MAJOR hang up. Items that use Aurelia's repeater don't show like normal composed custom elements. When I get to the repeat I just get a controller that is a "Repeat" controller, and it does not have a view that would let me know what controllers it has in it. Since this feature is on hold for now, could someone give me a hint on how to get to the "views" in a Repeat controller? In case it is useful, here is my overridden router view (CachedRouterView) that is trying to dig into the sub elements. Most of the relevant stuff starts with the call to "disableStartupMethodsForControllerChildern". |
@EisenbergEffect @jdanyow - I am about to start a significant overhaul on my application to work around this issue. I have spend significant amounts of time trying to "roll my own" on this and, while it may seem easy on the surface, significant knowledge of the inner working of Aurelia is needed to even get close. I am planning to split all my View Models (just under 20) and store all of the things that should be remembered between tab switches in external classes. My hope is that I can get the correct instance of these classes each time a new view model is made by Aurelia. The Aurelia view models will end up just performing Aurelia events/logic updates to the "real" view models. I don't want to do this (I am sure it will come with its own pack of bugs), but I keep having too many bugs that come down to this functionality/issue. Before I make this change, I just want to make sure that there is not hidden development that has been going on for this issue (where I could expect an update soon). (I am guessing not, since this has been open for 1 3/4 years.) |
I haven't had time to get back to this yet. I'd say your plan is a good approach either way. |
Does anyone know what the status of this as a built-in feature happens to be? |
@EisenbergEffect @jdanyow - please can we get an update/eta/confirmation this is dead? |
Originally, this was funded by a company specifically, but they decided to focus their funding in other areas. As a result, at the time, the work on this stopped. The core team is not actively investing in this above other areas of the router right now. We're always open to community contributions. As an alternative, you may want to consider using a portal to cache heavy screen components outside of the core view for certain routes. @bigopon has written a portal plugin for Aurelia and may have some thoughts on this. |
Note that the router can treat VMs as singletons to cache those. You can also implement |
Thanks for the detailed and upfront guidance. 😊 |
@jfstephe - just a word of warning. I tried to implement this. It looks as if is should work, but there are problems that cannot be resolved once you get into the details. See my post above for how I worked around this. What I did was a lot more work, but it functioned perfectly. |
@CedusJenkins @jfstephe Would #538 work for your use cases? |
@jwx - It sounds like it thanks. |
Currently, the aurelia router always re-create ViewModel and View when navigated. There doesn't seem to be an option in the router to cache the ViewModel and its associated View, avoiding them to be re-created in subsequent navigation. The benefit of caching is obvious: better user experience. It's also a common implementation used by top commercial apps, including iCloud.
Regarding experience, let's use iCloud as reference. Goto Mail, scroll down a few times, select a message. Now navigate to Contacts. Go back to Mail again, notice that everything is beautifully persisted. Aurelia router already have powerful capabilities, so I'd like to see caching options available, so achieving such experience will be a piece of cake.
Regarding the implementation, that won't be too hard. During swap, instead of replacing the old DOM with new one, we can store the old DOM and the respective ViewModel to a hidden container, or perhaps in-memory array. In subsequent navigation, if the View/VM already available, simply pick it up. In this case, I expect only activate cycle will be called, allowing me to perform additional operation in "re-entrance".
The text was updated successfully, but these errors were encountered: