@@ -8,6 +8,7 @@ function $StickyStateProvider($stateProvider) {
8
8
var inactiveStates = { } ; // state.name -> (state)
9
9
var stickyStates = { } ; // state.name -> true
10
10
var $state ;
11
+ var DEBUG = false ;
11
12
12
13
// Called by $stateProvider.registerState();
13
14
// registers a sticky state with $stickyStateProvider
@@ -16,8 +17,10 @@ function $StickyStateProvider($stateProvider) {
16
17
// console.log("Registered sticky state: ", state);
17
18
} ;
18
19
19
- this . enableDebug = function ( enabled ) {
20
- DEBUG = enabled ;
20
+ this . enableDebug = this . debugMode = function ( enabled ) {
21
+ if ( angular . isDefined ( enabled ) )
22
+ DEBUG = enabled ;
23
+ return DEBUG ;
21
24
} ;
22
25
23
26
this . $get = [ '$rootScope' , '$state' , '$stateParams' , '$injector' , '$log' ,
@@ -72,10 +75,11 @@ function $StickyStateProvider($stateProvider) {
72
75
// it as a Exit/Enter, thus the special "updateStateParams" transition.
73
76
// If a parent inactivated state has "updateStateParams" transition type, then
74
77
// all descendant states must also be exit/entered, thus the first line of this function.
75
- function getEnterTransition ( state , stateParams , ancestorParamsChanged ) {
78
+ function getEnterTransition ( state , stateParams , reloadStateTree , ancestorParamsChanged ) {
76
79
if ( ancestorParamsChanged ) return "updateStateParams" ;
77
80
var inactiveState = inactiveStates [ state . self . name ] ;
78
81
if ( ! inactiveState ) return "enter" ;
82
+ if ( state . self === reloadStateTree ) return "updateStateParams" ;
79
83
// if (inactiveState.locals == null || inactiveState.locals.globals == null) debugger;
80
84
var paramsMatch = equalForKeys ( stateParams , inactiveState . locals . globals . $stateParams , state . ownParams ) ;
81
85
// if (DEBUG) $log.debug("getEnterTransition: " + state.name + (paramsMatch ? ": reactivate" : ": updateStateParams"));
@@ -94,7 +98,7 @@ function $StickyStateProvider($stateProvider) {
94
98
// Duplicates logic in $state.transitionTo, primarily to find the pivot state (i.e., the "keep" value)
95
99
function equalForKeys ( a , b , keys ) {
96
100
if ( angular . isObject ( keys ) ) {
97
- keys = protoKeys ( keys , [ "$$keys" , "$$values" , "$$equals" , "$$validates" ] ) ;
101
+ keys = protoKeys ( keys , [ "$$keys" , "$$values" , "$$equals" , "$$validates" , "$$new" , "$$parent" ] ) ;
98
102
}
99
103
if ( ! keys ) {
100
104
keys = [ ] ;
@@ -133,6 +137,7 @@ function $StickyStateProvider($stateProvider) {
133
137
fromParams = transition . fromParams ,
134
138
toPath = transition . toState . path ,
135
139
toParams = transition . toParams ,
140
+ reloadStateTree = transition . reloadStateTree ,
136
141
options = transition . options ;
137
142
var keep = 0 , state = toPath [ keep ] ;
138
143
@@ -141,28 +146,29 @@ function $StickyStateProvider($stateProvider) {
141
146
}
142
147
143
148
while ( state && state === fromPath [ keep ] && equalForKeys ( toParams , fromParams , state . ownParams ) ) {
149
+ // We're "keeping" this state. bump keep var and get the next state in toPath for the next iteration.
144
150
state = toPath [ ++ keep ] ;
145
151
}
146
152
147
153
result . keep = keep ;
148
154
149
- var idx , deepestUpdatedParams , deepestReactivate , reactivatedStatesByName = { } , pType = getStickyTransitionType ( fromPath , toPath , keep ) ;
150
- var ancestorUpdated = false ; // When ancestor params change, treat reactivation as exit/enter
155
+ var idx , deepestUpdatedParams , deepestReactivate , noLongerInactiveStates = { } , pType = getStickyTransitionType ( fromPath , toPath , keep ) ;
156
+ var ancestorUpdated = ! ! options . reload ; // When ancestor params change, treat reactivation as exit/enter
151
157
152
158
// Calculate the "enter" transitions for new states in toPath
153
159
// Enter transitions will be either "enter", "reactivate", or "updateStateParams" where
154
160
// enter: full resolve, no special logic
155
161
// reactivate: use previous locals
156
162
// updateStateParams: like 'enter', except exit the inactive state before entering it.
157
163
for ( idx = keep ; idx < toPath . length ; idx ++ ) {
158
- var enterTrans = ! pType . to ? "enter" : getEnterTransition ( toPath [ idx ] , transition . toParams , ancestorUpdated ) ;
164
+ var enterTrans = ! pType . to ? "enter" : getEnterTransition ( toPath [ idx ] , toParams , reloadStateTree , ancestorUpdated ) ;
159
165
ancestorUpdated = ( ancestorUpdated || enterTrans == 'updateStateParams' ) ;
160
166
result . enter [ idx ] = enterTrans ;
161
167
// If we're reactivating a state, make a note of it, so we can remove that state from the "inactive" list
162
168
if ( enterTrans == 'reactivate' )
163
- deepestReactivate = reactivatedStatesByName [ toPath [ idx ] . name ] = toPath [ idx ] ;
169
+ deepestReactivate = noLongerInactiveStates [ toPath [ idx ] . name ] = toPath [ idx ] ;
164
170
if ( enterTrans == 'updateStateParams' )
165
- deepestUpdatedParams = toPath [ idx ] ;
171
+ deepestUpdatedParams = noLongerInactiveStates [ toPath [ idx ] . name ] = toPath [ idx ] ;
166
172
}
167
173
deepestReactivate = deepestReactivate ? deepestReactivate . self . name + "." : "" ;
168
174
deepestUpdatedParams = deepestUpdatedParams ? deepestUpdatedParams . self . name + "." : "" ;
@@ -181,7 +187,7 @@ function $StickyStateProvider($stateProvider) {
181
187
for ( var i = 0 ; inactiveChildren && i < inactiveChildren . length ; i ++ ) {
182
188
var child = inactiveChildren [ i ] ;
183
189
// Don't organize state as inactive if we're about to reactivate it.
184
- if ( ! reactivatedStatesByName [ child . name ] &&
190
+ if ( ! noLongerInactiveStates [ child . name ] &&
185
191
( ! deepestReactivate || ( child . self . name . indexOf ( deepestReactivate ) !== 0 ) ) &&
186
192
( ! deepestUpdatedParams || ( child . self . name . indexOf ( deepestUpdatedParams ) !== 0 ) ) )
187
193
result . inactives . push ( child ) ;
@@ -260,9 +266,9 @@ function $StickyStateProvider($stateProvider) {
260
266
} ,
261
267
262
268
// Removes a previously inactivated state from the inactive sticky state registry
263
- stateEntering : function ( entering , params , onEnter ) {
269
+ stateEntering : function ( entering , params , onEnter , updateParams ) {
264
270
var inactivatedState = getInactivatedState ( entering ) ;
265
- if ( inactivatedState && ! getInactivatedState ( entering , params ) ) {
271
+ if ( inactivatedState && ( updateParams || ! getInactivatedState ( entering , params ) ) ) {
266
272
var savedLocals = entering . locals ;
267
273
this . stateExiting ( inactivatedState ) ;
268
274
entering . locals = savedLocals ;
0 commit comments