Skip to content

Commit 111d259

Browse files
BREAKING CHANGE: Remove getResolveValue and getResolvable methods from Transition in favor of injector().get() and injector().getAsync()
In beta.3, the Transition APIs: `injector()`, `getResolvable`, and `getResolveValue` duplicated functionality. Instead of: ```js trans.getResolveValue('myResolve'); ``` use: ```js trans.injector().get('myResolve') ``` --- Instead of: ```js trans.getResolvable('myResolve').get(); ``` use: ```js trans.injector().getAsync('myResolve') ```
1 parent 0162212 commit 111d259

File tree

1 file changed

+20
-52
lines changed

1 file changed

+20
-52
lines changed

src/transition/transition.ts

+20-52
Original file line numberDiff line numberDiff line change
@@ -289,69 +289,37 @@ export class Transition implements IHookRegistry {
289289
/**
290290
* Gets all available resolve tokens (keys)
291291
*
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
293293
* available to the Transition.
294294
*
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
296296
* in the Transition's [[TreeChanges.to]] path.
297297
*
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+
* ```
312304
*
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+
* ```
315314
*
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()`
318316
*
319-
* @param token the token (or array of tokens)
320317
* @param pathname resolve context's path name (e.g., `to` or `from`)
321318
*
322319
* @returns an array of resolve tokens (keys)
323320
*/
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();
355323
}
356324

357325
/**

0 commit comments

Comments
 (0)