@@ -127,7 +127,7 @@ function $Resolve( $q, $injector) {
127
127
policyConf [ resolvable . name ] = resolvePolicies [ policyString ] ;
128
128
} ) ;
129
129
130
- var resolvablesForPolicy = filter ( resolvables , function ( resolvable ) { return policyConf [ resolvable . name ] >= policyOrdinal } ) ;
130
+ var resolvablesForPolicy = filter ( resolvables , function ( resolvable ) { return policyConf [ resolvable . name ] >= policyOrdinal ; } ) ;
131
131
return $q . all ( map ( resolvablesForPolicy , function ( resolvable ) { return resolvable . get ( resolveContext ) ; } ) ) ;
132
132
}
133
133
@@ -179,6 +179,9 @@ function $Resolve( $q, $injector) {
179
179
180
180
// statesOrPathElements must be an array of either state(s) or PathElement(s)
181
181
// states could be "public" state objects for this?
182
+ /*
183
+ Path becomes the replacement data structure for $state.$current.locals. This is now stored on the $transition closure in _fromPath.
184
+ */
182
185
Path = function Path ( statesOrPathElements ) {
183
186
var self = this ;
184
187
if ( ! isArray ( statesOrPathElements ) ) throw new Error ( "states must be an array of state(s) or PathElement(s)" , statesOrPathElements ) ;
@@ -199,32 +202,10 @@ function $Resolve( $q, $injector) {
199
202
function resolveContext ( toPathElement ) {
200
203
toPathElement = toPathElement || elements [ elements . length - 1 ] ;
201
204
var elementIdx = elements . indexOf ( toPathElement ) ;
202
- // if (angular.isNumber(toPathElement)) // maybe allow the param to be the index too
203
- // elementIdx = toPathElement;
204
205
if ( elementIdx == - 1 ) throw new Error ( "this Path does not contain the toPathElement" ) ;
205
206
return new ResolveContext ( self . slice ( 0 , elementIdx ) ) ;
206
207
}
207
208
208
- // Not used
209
- function invoke ( hook , self , locals ) {
210
- if ( ! hook ) return ;
211
- return $injector . invoke ( hook , self , locals ) ;
212
- }
213
-
214
- function invokeFunctionsSync ( path , fnName , reverse ) {
215
- var pathElements = elements . slice ( 0 ) ;
216
- if ( reverse ) pathElements . reverse ( ) ;
217
-
218
- forEach ( pathElements , function ( pathElement ) {
219
- var fn = pathElement . state [ fnName ] ;
220
- if ( fn ) {
221
- var result = pathElement . invokeNow ( fn , { } , path . resolveContext ( pathElement ) ) ;
222
- if ( ! result ) return result ;
223
- }
224
- } ) ;
225
- return true ;
226
- }
227
-
228
209
// Public API
229
210
extend ( this , {
230
211
resolve : resolvePath ,
@@ -242,67 +223,63 @@ function $Resolve( $q, $injector) {
242
223
} ,
243
224
states : function ( ) {
244
225
return pluck ( elements , "state" ) ;
245
- } ,
246
- $$enter : function ( toPath , async ) {
247
- // Async returns promise for true/false. Don't need to pre-resolve anything
248
- if ( async ) return invokeFunctionsAsync ( toPath , 'onEnter' , false ) ;
249
- // Sync returns truthy/falsy ... all deps must be pre-resolved in toPath
250
- if ( async )
251
- return invokeFunctionsSync ( toPath , 'onEnter' , false ) ;
252
- } ,
253
- $$exit : function ( fromPath , async ) {
254
- if ( async ) return invokeFunctionsAsync ( fromPath , 'onExit' , true ) ;
255
- return invokeFunctionsSync ( fromPath , 'onExit' , true ) ;
256
226
}
257
227
} ) ;
258
228
} ;
259
229
260
- // ResolveContext is passed into each resolve() function, and is used to statefully manage Resolve status.
261
- // ResolveContext is essentially the replacement data structure for $state.$current.locals and we'll have to
262
- // figure out where to store/manage this data structure .
263
- // It manages a set of Resolvables that are available at each level of the Path.
264
- // It follows the list of PathElements and inherit()s the PathElement's Resolvables on top of the
265
- // previous PathElement's Resolvables. i.e., it builds a prototypal chain for the PathElements' Resolvables .
266
- // Before moving on to the next PathElement, it makes a note of what Resolvables are available for the current
267
- // PathElement, and maps it by state name.
268
-
269
- // ResolveContext constructor takes a path which is assumed to be partially resolved, or
270
- // not resolved at all, which we're in process of resolving
230
+ /**
231
+ * ResolveContext provides injectable dependencies (Resolvables) to the three resolve() functions (Path.resolve,
232
+ * PathElement.resolve, and Resolvable.resolve) .
233
+ *
234
+ * The ResolveContext constructor takes a Path(), from which the ResolvableContext is built. The Path contains
235
+ * PathElements, which each in turn contain a Resolvables map. Each Resolvable may or may not be pre-resolved .
236
+ *
237
+ * For each PathElement in the Path, ResolveContext maps the available Resolvables. Each PathElement is provided with
238
+ * the Resolvables at its own level, as well as the aggregated Resolvables of its parent PathElement(s). Aggregation is
239
+ * done using prototypal inheritance from the parent's Resolvable(s) map.
240
+ */
271
241
ResolveContext = function ResolveContext ( path ) {
272
242
if ( path === undefined ) path = new Path ( [ ] ) ;
273
243
var resolvablesByState = { } , previousIteration = { } ;
274
244
275
245
forEach ( path . elements , function ( pathElem ) {
276
246
var resolvablesForPE = pathElem . resolvables ;
277
- var resolvesbyName = indexBy ( resolvablesForPE , 'name' ) ;
278
- var resolvables = inherit ( previousIteration , resolvesbyName ) ; // note prototypal inheritance
247
+ var resolvesByName = indexBy ( resolvablesForPE , 'name' ) ;
248
+ var resolvables = inherit ( previousIteration , resolvesByName ) ; // note prototypal inheritance
279
249
previousIteration = resolvablesByState [ pathElem . state . name ] = resolvables ;
280
250
} ) ;
281
251
282
- // Gets resolvables available for a particular state.
283
- // TODO: This should probably be "for a particular PathElement" instead of state, but PathElements encapsulate a state.
284
- // This returns the Resolvable map by state name.
285
-
286
- // options.omitPropsFromPrototype
287
- // Remove the props specified in options.omitPropsFromPrototype from the prototype of the object.
288
-
289
- // This hides a top-level resolvable by name, potentially exposing a parent resolvable of the same name
290
- // further down the prototype chain.
291
-
292
- // This is used to provide a Resolvable access to all other Resolvables in its same PathElement, yet disallow
293
- // that Resolvable access to its own injectable Resolvable reference.
294
-
295
- // This is also used to allow a state to override a parent state's resolve while also injecting
296
- // that parent state's resolve:
297
252
298
- // state({ name: 'G', resolve: { _G: function() { return "G"; } } });
299
- // state({ name: 'G.G2', resolve: { _G: function(_G) { return _G + "G2"; } } });
300
- // where injecting _G into a controller will yield "GG2"
301
253
302
- // options.flatten
303
- // $$resolvablesByState has resolvables organized in a prototypal inheritance chain. options.flatten will
304
- // flatten the object from prototypal inheritance to a simple object with all its prototype chain properties
305
- // exposed with child properties taking precedence over parent properties.
254
+ /**
255
+ * Gets the available Resolvables for a particular PathElement (mapped by the PathElement's state name).
256
+ *
257
+ * @param stateName
258
+ * @param options
259
+ *
260
+ * options.flatten
261
+ * Return the Resolvables as a standard object map, not a prototypally inherited object map.
262
+ *
263
+ * $$resolvablesByState has resolvables organized in a prototypal inheritance chain. options.flatten will
264
+ * flatten the object from prototypal inheritance to a simple object with all its prototype chain properties
265
+ * exposed, where child properties take precedence over parent properties.
266
+ *
267
+ * options.omitPropsFromPrototype
268
+ * Remove the props specified in options.omitPropsFromPrototype from the prototype of the object.
269
+ *
270
+ * This will hide a top-level resolvable (by name), potentially exposing a parent resolvable of the same name
271
+ * further down the prototype chain.
272
+ *
273
+ * This is used by Resolvable.resolve(resolveContext) in order to provide the Resolvable access to all the other
274
+ * Resolvables at its own PathElement level, yet disallow that Resolvable access to its own injectable Resolvable.
275
+ *
276
+ * This is also used to allow a state to override a parent state's resolve while also injecting
277
+ * that parent state's resolve:
278
+ *
279
+ * state({ name: 'G', resolve: { _G: function() { return "G"; } } });
280
+ * state({ name: 'G.G2', resolve: { _G: function(_G) { return _G + "G2"; } } });
281
+ * where injecting _G into a controller will yield "GG2"
282
+ */
306
283
function getResolvableLocals ( stateName , options ) {
307
284
var resolvables = ( resolvablesByState [ stateName ] || { } ) ;
308
285
options = extend ( { flatten : true , omitPropsFromPrototype : [ ] } , options ) ;
0 commit comments