Skip to content
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

reload option in transitionTo reloads all states in a hierarchy. Unable to reload just the current nested state. #1612

Closed
gfreeau opened this issue Dec 6, 2014 · 15 comments
Assignees
Labels
Milestone

Comments

@gfreeau
Copy link

gfreeau commented Dec 6, 2014

When using the reload option in state.transitionTo on a nested state, all of its parents are also reloaded. You should be able to reload only the current state.

My use case is a nested state with params. In some cases I have the same state and params and I simply wish to reload it (to refresh data from the server), however using the reload option also reloads it's parents, which resets templates and directives in parent states.

One workaround I found is to have some kind of random param in the nested state which is changed every time you wish to reload/refresh the current state. UI-Router seems to handle the case fine when a state has unique params every time, it just cannot reload a state with the exact same params since it believes there is no work to do.

Here is what happens:

  • Nested state, no changes to params = UI router does nothing, since it assumes it is already on the correct state
  • Nested state, with an additional unique param assigned to a random value to uniquely identify every transitionTo call = works correctly, able to "refresh" nested states without reloading parents
  • using the reload option, refreshes the nested state correctly but also reloads all parents

I can setup a plunk, I just wanted to see if this is worthwhile first.

@ProLoser
Copy link
Member

ProLoser commented Dec 7, 2014

What if reload to a string name of the state at which you want to reload?

state1.state2.state3

reload: false // default behavior
reload: true // full tree reload
reload: 'state3' // only last child is reloaded
reload: 'state2' // state2 and deeper (state3) are reloaded

Alternatively, is this really an issue about transitioning? Or do you just want to reload a state you're already sitting in? In which case, should we be looking at a reload() method directly and it's behavior (which of course could possibly be a reflection of the two truthy versions above so as to allow code reuse).

@gfreeau
Copy link
Author

gfreeau commented Dec 8, 2014

@ProLoser, It's not directly related to transitioning, it'a about reloading the controller/resolves for a state with the goal of refreshing data in the current state.

However it would be solved if we could reload selected states or a partial hierarchy of states, which would in turn reload the controllers/resolves.

@gfreeau
Copy link
Author

gfreeau commented Dec 10, 2014

Just wanted to share my work-around for reloading partial states. First of all don't use the reload option at all. Create a parameter for the state such as

params: {
    uniqueRequestCacheBuster: null
}

Then if you ever need to reload the current state without parents using the same parameters, you can do it with transitionTo

var params = angular.copy($stateParams);
params.uniqueRequestCacheBuster = Math.random();

$state.transitionTo($state.current, params);

The cache buster parameter will not show up in the URL.

UI-Router natively handles reloading only partial hierarchies of states when url parameters are changed. if you use the reload option, it will reload all parents as well.

This works thanks to @christopherthielen work on params.

@ProLoser
Copy link
Member

I would still prefer to see reload take a string value.

@gfreeau
Copy link
Author

gfreeau commented Dec 10, 2014

That is a better option longer term.

@christopherthielen
Copy link
Contributor

Seem reasonable

@Astray-git
Copy link

I have a similar problem with the reload. I use resolves to update data in my state's controller.(when it's an active state)
I use the params work-around above, it does reload the resolves, but doesn't reinitialize the controller, the injected resolve is not updated. I also tried transition with options
{ reload: true, inherit: false, notify: true } which didn't work neither.

@deanapeterson
Copy link

The ability to set the descendant depth of the reload is an excellent idea.

@oriweingart
Copy link
Contributor

We implemented this feature for a private project.
PR was created: #1795
Welcome to try it..

@christopherthielen
Copy link
Contributor

I think this makes sense and is a good idea. I'd like to omit the second reloadState parameter, and overload the existing reload parameter.

  • { reload: true }// reloads all,
  • { reload: 'foo.bar' } // reloads top.bar, and any children
  • { reload: stateObj } // reloads state found in stateObj, and any children

Squash your commits and set your commit message to match the contributor guidelines. If @nateabele concurs, I think we'll merge this in.

@oriweingart
Copy link
Contributor

Created a new PR according to your comments: #1809

@christopherthielen christopherthielen added this to the 0.2.14 milestone Mar 29, 2015
@nateabele
Copy link
Contributor

Fixed in #1809.

ns-codereview pushed a commit to couchbase/ns_server that referenced this issue Apr 8, 2015
In this implementation the launchpad will be called each
time when we call reloadState. This is not exactly
how the launchpad working in cell based implementation, but
ability to set the descendant depth of the reload would be
very useful for the lunchpad functionality and for mnApp in general.
Next release of ui-router has all chance to contain what we need.
angular-ui/ui-router#1612.

Change-Id: If25a8f98dfe5aaea1be7eaff5b398802fb6d122c
Reviewed-on: http://review.couchbase.org/46940
Reviewed-by: Pavel Blagodov <[email protected]>
Tested-by: Pavel Blagodov <[email protected]>
@shyamal890
Copy link

+1 Was looking this since long back. Thank you.

@DumboJet
Copy link

DumboJet commented Jun 7, 2016

Can reload accept a list of states to reload?
Or it is too much to ask?

{ reload: ['foo.bar','foo.bar.car.jar'] }

@ProLoser
Copy link
Member

ProLoser commented Jun 7, 2016

@DumboJet that doesn't make any sense since reloading a parent state reloads the descendents

@angular-ui angular-ui locked and limited conversation to collaborators Jun 7, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

9 participants