ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

feat: cached states/nav-views and ui-router resolves

Open RBLU opened this issue 11 years ago • 3 comments

Type: feat

Platform: all

in ionic 1.0.0 when a ui-router state has cache: true (or also just the default value meaning cache: true):

  • resolves are executed again when I transition back to a previously cached state
  • but the result of these fresh resolves is not easily accessible (even though they can be retrieved by injecting $state and accessing $state.$current.locals.resolve.then(function(resolves) {...

This does not make sense to me, either we should not execute the resolves when we transition back to a cached state, or we should make the result of the fresh resolves easily available throught the enteringData of the $ionicView.enter event.

So I am unsure about the intended behaviour.

For the current behaviour (executing resolves upon transitioning into a cached state) I suggest to add the following line to ionicViewSwitcher.transition function: https://github.com/driftyco/ionic/blob/master/js/angular/service/viewSwitcher.js#L153-L154

enteringData.resolves = viewLocals:

to provide acces to the fresh resolves.

Please advise whether this is a good idea, i will happily provide a PR

RBLU avatar Jun 09 '15 13:06 RBLU

Could you provide a codepen demonstrating this?

mhartington avatar Jun 11 '15 18:06 mhartington

see here: http://codepen.io/anon/pen/OVgQQx

switch between state 1 und state 2 several times and look at the JS console:

  • see how state 1 is cached (controller 1 is only executed once)
  • but resolve 1 is executed every time you enter state 1
  • there is currently no easy way to retrieve the result of this resolve

(I don't understand why state 2 is not being cached in this codepen (controller 2 is executed every time), but that is a different issue)

RBLU avatar Jun 11 '15 19:06 RBLU

Ok, so view 2 isn't getting cached because we don't cache forward views be default.

http://ionicframework.com/docs/api/provider/$ionicConfigProvider/#views.forwardCache

As for the resolve, I'm not sure we'd be able to fix that. That's at UI-router's level and would require us to hack ui-router (no ideal). Probably best to just push that logic to controller and not use a resolve for now.

mhartington avatar Jun 11 '15 20:06 mhartington