@@ -8,19 +8,34 @@ import {Resolvable} from "../resolve/resolvable";
8
8
import { ResolveContext } from "../resolve/resolveContext" ;
9
9
import { ViewConfig } from "../view/interface" ;
10
10
11
- export class Node {
11
+ /**
12
+ * A node in a [[TreeChanges]] path
13
+ *
14
+ * For a [[TreeChanges]] path, this class holds the stateful information for a single node in the path.
15
+ * Each PathNode corresponds to a state being entered, exited, or retained.
16
+ * The stateful information includes parameter values and resolve data.
17
+ */
18
+ export class PathNode {
19
+ /** The state being entered, exited, or retained */
12
20
public state : State ;
21
+ /** The parameters declared on the state */
13
22
public paramSchema : Param [ ] ;
23
+ /** The parameter values that belong to the state */
14
24
public paramValues : { [ key : string ] : any } ;
25
+ /** A context object used in conjunction with [[resolvables]] to manage resolves */
26
+ public resolveContext : ResolveContext ;
27
+ /** The individual (stateful) resolvable objects that belong to the state */
15
28
public resolvables : Resolvable [ ] ;
29
+ /** The state's declared view configuration objects */
16
30
public views : ViewConfig [ ] ;
17
- public resolveContext : ResolveContext ;
18
31
19
- constructor ( state : Node ) ;
32
+ /** Creates a copy of a PathNode */
33
+ constructor ( state : PathNode ) ;
34
+ /** Creates a new (empty) PathNode for a State */
20
35
constructor ( state : State ) ;
21
36
constructor ( state ) {
22
- if ( state instanceof Node ) {
23
- let node : Node = state ;
37
+ if ( state instanceof PathNode ) {
38
+ let node : PathNode = state ;
24
39
this . state = node . state ;
25
40
this . paramSchema = node . paramSchema . slice ( ) ;
26
41
this . paramValues = extend ( { } , node . paramValues ) ;
@@ -35,23 +50,30 @@ export class Node {
35
50
}
36
51
}
37
52
38
- applyRawParams ( params : RawParams ) : Node {
53
+ /** Sets [[paramValues]] for the node, from the values of an object hash */
54
+ applyRawParams ( params : RawParams ) : PathNode {
39
55
const getParamVal = ( paramDef : Param ) => [ paramDef . id , paramDef . value ( params [ paramDef . id ] ) ] ;
40
56
this . paramValues = this . paramSchema . reduce ( ( memo , pDef ) => applyPairs ( memo , getParamVal ( pDef ) ) , { } ) ;
41
57
return this ;
42
58
}
43
59
60
+ /** Gets a specific [[Param]] metadata that belongs to the node */
44
61
parameter ( name : string ) : Param {
45
62
return find ( this . paramSchema , propEq ( "id" , name ) ) ;
46
63
}
47
64
48
- equals ( node : Node , keys = this . paramSchema . map ( prop ( 'id' ) ) ) : boolean {
65
+ /**
66
+ * @returns true if the state and parameter values for another PathNode are
67
+ * equal to the state and param values for this PathNode
68
+ */
69
+ equals ( node : PathNode , keys = this . paramSchema . map ( prop ( 'id' ) ) ) : boolean {
49
70
const paramValsEq = key => this . parameter ( key ) . type . equals ( this . paramValues [ key ] , node . paramValues [ key ] ) ;
50
71
return this . state === node . state && keys . map ( paramValsEq ) . reduce ( allTrueR , true ) ;
51
72
}
52
73
53
- static clone ( node : Node ) {
54
- return new Node ( node ) ;
74
+ /** Returns a clone of the PathNode */
75
+ static clone ( node : PathNode ) {
76
+ return new PathNode ( node ) ;
55
77
}
56
78
57
79
/**
@@ -60,17 +82,17 @@ export class Node {
60
82
* The new path starts from root and contains any nodes that match the nodes in the second path.
61
83
* Nodes are compared using their state property and parameter values.
62
84
*/
63
- static matching ( pathA : Node [ ] , pathB : Node [ ] ) : Node [ ] {
85
+ static matching ( pathA : PathNode [ ] , pathB : PathNode [ ] ) : PathNode [ ] {
64
86
let matching = [ ] ;
65
-
87
+
66
88
for ( let i = 0 ; i < pathA . length && i < pathB . length ; i ++ ) {
67
89
let a = pathA [ i ] , b = pathB [ i ] ;
68
-
90
+
69
91
if ( a . state !== b . state ) break ;
70
92
if ( ! Param . equals ( a . paramSchema , a . paramValues , b . paramValues ) ) break ;
71
93
matching . push ( a ) ;
72
94
}
73
-
95
+
74
96
return matching
75
97
}
76
98
}
0 commit comments