Skip to content

Commit

Permalink
feat(Transition): Allow a plain object ResolvableLiteral in `Transi…
Browse files Browse the repository at this point in the history
…tion.addResolvable`
  • Loading branch information
christopherthielen committed Jan 7, 2017
1 parent 111d259 commit ad9ae81
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/transition/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
omit, toJson, arrayTuples, unnestR, identity, anyTrueR
} from "../common/common";
import { isObject, isArray } from "../common/predicates";
import { prop, propEq, val, not } from "../common/hof";
import { prop, propEq, val, not, is } from "../common/hof";

import {StateDeclaration, StateOrName} from "../state/interface";
import {
Expand All @@ -36,6 +36,7 @@ import {UIRouter} from "../router";
import {Globals} from "../globals";
import {UIInjector} from "../interface";
import {RawParams} from "../params/interface";
import { ResolvableLiteral } from "../resolve/interface";

/** @hidden */
const stateSelf: (_state: State) => StateDeclaration = prop("self");
Expand Down Expand Up @@ -323,17 +324,19 @@ export class Transition implements IHookRegistry {
}

/**
* Dynamically adds a new [[Resolvable]] (`resolve`) to this transition.
* Dynamically adds a new [[Resolvable]] (i.e., [[StateDeclaration.resolve]]) to this transition.
*
* @param resolvable an [[Resolvable]] object
* @param resolvable a [[ResolvableLiteral]] object (or a [[Resolvable]])
* @param state the state in the "to path" which should receive the new resolve (otherwise, the root state)
*/
addResolvable(resolvable: Resolvable, state: StateOrName = ""): void {
addResolvable(resolvable: Resolvable|ResolvableLiteral, state: StateOrName = ""): void {
resolvable = is(Resolvable)(resolvable) ? resolvable : new Resolvable(resolvable);

let stateName: string = (typeof state === "string") ? state : state.name;
let topath = this._treeChanges.to;
let targetNode = find(topath, node => node.state.name === stateName);
let resolveContext: ResolveContext = new ResolveContext(topath);
resolveContext.addResolvables([resolvable], targetNode.state);
resolveContext.addResolvables([resolvable as Resolvable], targetNode.state);
}

/**
Expand Down

0 comments on commit ad9ae81

Please sign in to comment.