1
1
/// <reference path='../../typings/angularjs/angular.d.ts' />
2
2
3
- import { extend , isArray , isString , identity , noop , Predicate ,
4
- defaults , map , omit , pluck , find , pipe , prop , eq } from "../common/common" ;
5
- import trace from "../common/trace" ;
6
- import { runtime } from "../common/angular1"
7
- import { IPromise } from "angular" ;
8
-
9
- import { INode , IParamsNode , IParamsPath } from "./interface" ;
3
+ import { extend , isString , find , pipe , parse , prop , eq } from "../common/common" ;
4
+ import { INode } from "./interface" ;
10
5
11
6
import { IState , IStateDeclaration , IStateOrName } from "../state/interface" ;
12
- import TargetState from "../state/targetState"
13
-
14
- import { IResolvables } from "../resolve/interface" ;
15
- import Resolvable from "../resolve/resolvable" ;
16
7
17
8
const stateMatches = ( state : IState | IStateDeclaration ) => ( node ) => node . state === state || node . state . self === state ;
18
9
const stateNameMatches = ( stateName : string ) => ( node ) => node . state . name === stateName ;
@@ -39,9 +30,9 @@ export default class Path<NODE extends INode> {
39
30
*/
40
31
pathFromRootTo ( toState : IStateOrName ) : Path < NODE > {
41
32
let predicate = isString ( toState ) ? stateNameMatches ( < string > toState ) : stateMatches ( < IState > toState ) ;
42
- var node = find ( this . _nodes , predicate ) ;
43
- var elementIdx = this . _nodes . indexOf ( node ) ;
44
- if ( elementIdx == - 1 ) throw new Error ( "This Path does not contain the toPathElement" ) ;
33
+ let node = find ( this . _nodes , predicate ) ;
34
+ let elementIdx = this . _nodes . indexOf ( node ) ;
35
+ if ( elementIdx === - 1 ) throw new Error ( "This Path does not contain the toPathElement" ) ;
45
36
return this . slice ( 0 , elementIdx + 1 ) ;
46
37
}
47
38
@@ -77,8 +68,9 @@ export default class Path<NODE extends INode> {
77
68
}
78
69
79
70
/** Gets the first node that exactly matches the given state */
80
- nodeForState ( state : IState ) : NODE {
81
- return find ( this . _nodes , pipe ( prop ( 'state' ) , eq ( state ) ) ) ;
71
+ nodeForState ( state : IStateOrName ) : NODE {
72
+ let propName = ( isString ( state ) ? "state.name" : "state" ) ;
73
+ return find ( this . _nodes , pipe ( parse ( propName ) , eq ( state ) ) ) ;
82
74
}
83
75
84
76
/** Returns the Path's nodes wrapped in a new array */
0 commit comments