@@ -289,69 +289,37 @@ export class Transition implements IHookRegistry {
289
289
/**
290
290
* Gets all available resolve tokens (keys)
291
291
*
292
- * This method can be used in conjunction with [[getResolve ]] to inspect the resolve values
292
+ * This method can be used in conjunction with [[injector ]] to inspect the resolve values
293
293
* available to the Transition.
294
294
*
295
- * The returned tokens include those defined on [[StateDeclaration.resolve]] blocks, for the states
295
+ * This returns all the tokens defined on [[StateDeclaration.resolve]] blocks, for the states
296
296
* in the Transition's [[TreeChanges.to]] path.
297
297
*
298
- * @param pathname resolve context's path name (e.g., `to` or `from`)
299
- *
300
- * @returns an array of resolve tokens (keys)
301
- */
302
- getResolveTokens ( pathname : string = "to" ) : any [ ] {
303
- return new ResolveContext ( this . _treeChanges [ pathname ] ) . getTokens ( ) ;
304
- }
305
-
306
-
307
- /**
308
- * Gets resolved values
309
- *
310
- * This method can be used in conjunction with [[getResolveTokens]] to inspect what resolve values
311
- * are available to the Transition.
298
+ * #### Example:
299
+ * This example logs all resolve values
300
+ * ```js
301
+ * let tokens = trans.getResolveTokens();
302
+ * tokens.forEach(token => console.log(token + " = " + trans.injector().get(token)));
303
+ * ```
312
304
*
313
- * Given a token, returns the resolved data for that token.
314
- * Given an array of tokens, returns an array of resolved data for those tokens.
305
+ * #### Example:
306
+ * This example creates promises for each resolve value.
307
+ * This triggers fetches of resolves (if any have not yet been fetched).
308
+ * When all promises have all settled, it logs the resolve values.
309
+ * ```js
310
+ * let tokens = trans.getResolveTokens();
311
+ * let promise = tokens.map(token => trans.injector().getAsync(token));
312
+ * Promise.all(promises).then(values => console.log("Resolved values: " + values));
313
+ * ```
315
314
*
316
- * If a resolvable hasn't yet been fetched, returns `undefined` for that token
317
- * If a resolvable doesn't exist for the token, throws an error.
315
+ * Note: Angular 1 users whould use `$q.all()`
318
316
*
319
- * @param token the token (or array of tokens)
320
317
* @param pathname resolve context's path name (e.g., `to` or `from`)
321
318
*
322
319
* @returns an array of resolve tokens (keys)
323
320
*/
324
- getResolveValue ( token : any [ ] , pathname ?: string ) : any [ ] ;
325
- getResolveValue ( token : any , pathname ?: string ) : any ;
326
- getResolveValue ( token : ( any | any [ ] ) , pathname : string = "to" ) : ( any | any [ ] ) {
327
- let resolveContext = new ResolveContext ( this . _treeChanges [ pathname ] ) ;
328
- const getData = ( token : any ) => {
329
- var resolvable = resolveContext . getResolvable ( token ) ;
330
- if ( resolvable === undefined ) {
331
- throw new Error ( `Dependency Injection token not found: ${ stringify ( token ) } ` ) ;
332
- }
333
- return resolvable . data ;
334
- } ;
335
-
336
- if ( isArray ( token ) ) {
337
- return token . map ( getData ) ;
338
- }
339
-
340
- return getData ( token ) ;
341
- }
342
-
343
- /**
344
- * Gets a [[Resolvable]] primitive
345
- *
346
- * This is a lower level API that returns a [[Resolvable]] from the Transition for a given token.
347
- *
348
- * @param token the DI token
349
- * @param pathname resolve context's path name (e.g., `to` or `from`)
350
- *
351
- * @returns the [[Resolvable]] in the transition's to path, or undefined
352
- */
353
- getResolvable ( token : any , pathname = "to" ) : Resolvable {
354
- return new ResolveContext ( this . _treeChanges [ pathname ] ) . getResolvable ( token ) ;
321
+ getResolveTokens ( pathname : string = "to" ) : any [ ] {
322
+ return new ResolveContext ( this . _treeChanges [ pathname ] ) . getTokens ( ) ;
355
323
}
356
324
357
325
/**
0 commit comments