Skip to content

Commit

Permalink
BREAKING CHANGE: Remove getResolveValue and getResolvable methods…
Browse files Browse the repository at this point in the history
… 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')
```
  • Loading branch information
christopherthielen committed Jan 7, 2017
1 parent 0162212 commit 111d259
Showing 1 changed file with 20 additions and 52 deletions.
72 changes: 20 additions & 52 deletions src/transition/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,69 +289,37 @@ export class Transition implements IHookRegistry {
/**
* Gets all available resolve tokens (keys)
*
* This method can be used in conjunction with [[getResolve]] to inspect the resolve values
* This method can be used in conjunction with [[injector]] to inspect the resolve values
* available to the Transition.
*
* The returned tokens include those defined on [[StateDeclaration.resolve]] blocks, for the states
* This returns all the tokens defined on [[StateDeclaration.resolve]] blocks, for the states
* in the Transition's [[TreeChanges.to]] path.
*
* @param pathname resolve context's path name (e.g., `to` or `from`)
*
* @returns an array of resolve tokens (keys)
*/
getResolveTokens(pathname: string = "to"): any[] {
return new ResolveContext(this._treeChanges[pathname]).getTokens();
}


/**
* Gets resolved values
*
* This method can be used in conjunction with [[getResolveTokens]] to inspect what resolve values
* are available to the Transition.
* #### Example:
* This example logs all resolve values
* ```js
* let tokens = trans.getResolveTokens();
* tokens.forEach(token => console.log(token + " = " + trans.injector().get(token)));
* ```
*
* Given a token, returns the resolved data for that token.
* Given an array of tokens, returns an array of resolved data for those tokens.
* #### Example:
* This example creates promises for each resolve value.
* This triggers fetches of resolves (if any have not yet been fetched).
* When all promises have all settled, it logs the resolve values.
* ```js
* let tokens = trans.getResolveTokens();
* let promise = tokens.map(token => trans.injector().getAsync(token));
* Promise.all(promises).then(values => console.log("Resolved values: " + values));
* ```
*
* If a resolvable hasn't yet been fetched, returns `undefined` for that token
* If a resolvable doesn't exist for the token, throws an error.
* Note: Angular 1 users whould use `$q.all()`
*
* @param token the token (or array of tokens)
* @param pathname resolve context's path name (e.g., `to` or `from`)
*
* @returns an array of resolve tokens (keys)
*/
getResolveValue(token: any[], pathname?: string): any[];
getResolveValue(token: any, pathname?: string): any;
getResolveValue(token: (any|any[]), pathname: string = "to"): (any|any[]) {
let resolveContext = new ResolveContext(this._treeChanges[pathname]);
const getData = (token: any) => {
var resolvable = resolveContext.getResolvable(token);
if (resolvable === undefined) {
throw new Error(`Dependency Injection token not found: ${stringify(token)}`);
}
return resolvable.data;
};

if (isArray(token)) {
return token.map(getData);
}

return getData(token);
}

/**
* Gets a [[Resolvable]] primitive
*
* This is a lower level API that returns a [[Resolvable]] from the Transition for a given token.
*
* @param token the DI token
* @param pathname resolve context's path name (e.g., `to` or `from`)
*
* @returns the [[Resolvable]] in the transition's to path, or undefined
*/
getResolvable(token: any, pathname = "to"): Resolvable {
return new ResolveContext(this._treeChanges[pathname]).getResolvable(token);
getResolveTokens(pathname: string = "to"): any[] {
return new ResolveContext(this._treeChanges[pathname]).getTokens();
}

/**
Expand Down

0 comments on commit 111d259

Please sign in to comment.