1
1
/** @module path */ /** for typedoc */
2
2
3
3
import { extend , find , pick , omit , tail , mergeR , values , unnestR } from "../common/common" ;
4
- import { prop , propEq , not , curry } from "../common/hof" ;
4
+ import { prop , propEq , not } from "../common/hof" ;
5
5
6
6
import { RawParams } from "../params/interface" ;
7
7
import { TreeChanges } from "../transition/interface" ;
8
+ import { ViewConfig } from "../view/interface" ;
9
+ import { _ViewDeclaration } from "../state/interface" ;
8
10
9
11
import { State , TargetState } from "../state/module" ;
10
12
import { Node } from "../path/node" ;
11
- import { ResolveContext , Resolvable } from "../resolve/module" ;
12
- import { Transition } from "../transition/module" ;
13
+ import { ResolveContext } from "../resolve/module" ;
13
14
import { ViewService } from "../view/view" ;
14
15
15
16
/**
@@ -38,12 +39,18 @@ export class PathFactory {
38
39
}
39
40
return toPath ;
40
41
}
41
-
42
+
43
+ /**
44
+ * Creates ViewConfig objects and adds to nodes.
45
+ *
46
+ * On each Node, creates ViewConfig objects from the views: property of the node's state
47
+ */
42
48
static applyViewConfigs ( $view : ViewService , path : Node [ ] ) {
43
49
return path . map ( node => {
44
- let viewDecls = values ( node . state . views || { } ) ;
45
- let viewConfigs = viewDecls . map ( view => $view . createViewConfig ( node , view ) ) . reduce ( unnestR , [ ] ) ;
46
- return extend ( node , { views : viewConfigs } )
50
+ let viewDecls : _ViewDeclaration [ ] = values ( node . state . views || { } ) ;
51
+ let viewConfigs : ViewConfig [ ] [ ] = viewDecls . map ( view => $view . createViewConfig ( node , view ) ) ;
52
+ node . views = viewConfigs . reduce ( unnestR , [ ] ) ;
53
+ return node ;
47
54
} ) ;
48
55
}
49
56
@@ -68,39 +75,32 @@ export class PathFactory {
68
75
* Given an Node "toNode", return a new Node with param values inherited from the
69
76
* matching node in fromPath. Only inherit keys that aren't found in "toKeys" from the node in "fromPath""
70
77
*/
71
- let makeInheritedParamsNode = curry ( function ( _fromPath : Node [ ] , _toKeys : string [ ] , toNode : Node ) : Node {
78
+ function makeInheritedParamsNode ( toNode : Node ) : Node {
72
79
// All param values for the node (may include default key/vals, when key was not found in toParams)
73
80
let toParamVals = extend ( { } , toNode && toNode . paramValues ) ;
74
81
// limited to only those keys found in toParams
75
- let incomingParamVals = pick ( toParamVals , _toKeys ) ;
76
- toParamVals = omit ( toParamVals , _toKeys ) ;
77
- let fromParamVals = nodeParamVals ( _fromPath , toNode . state ) || { } ;
82
+ let incomingParamVals = pick ( toParamVals , toKeys ) ;
83
+ toParamVals = omit ( toParamVals , toKeys ) ;
84
+ let fromParamVals = nodeParamVals ( fromPath , toNode . state ) || { } ;
78
85
// extend toParamVals with any fromParamVals, then override any of those those with incomingParamVals
79
86
let ownParamVals : RawParams = extend ( toParamVals , fromParamVals , incomingParamVals ) ;
80
87
return new Node ( toNode . state ) . applyRawParams ( ownParamVals ) ;
81
- } ) ;
88
+ }
82
89
83
90
// The param keys specified by the incoming toParams
84
- return < Node [ ] > toPath . map ( makeInheritedParamsNode ( fromPath , toKeys ) ) ;
91
+ return < Node [ ] > toPath . map ( makeInheritedParamsNode ) ;
85
92
}
86
93
87
94
/**
88
- * Given a path, upgrades the path to a Node[]. Each node is assigned a ResolveContext
89
- * and ParamValues object which is bound to the whole path, but closes over the subpath from root to the node.
90
- * The views are also added to the node.
95
+ * Given a path of nodes, creates and binds a ResolveContext to each node.
96
+ * The ResolveContext is used to inject functions from the proper scoping in the resolve tree.
91
97
*/
92
- static bindTransNodesToPath ( resolvePath : Node [ ] ) : Node [ ] {
98
+ static bindResolveContexts ( resolvePath : Node [ ] ) : Node [ ] {
93
99
let resolveContext = new ResolveContext ( resolvePath ) ;
94
- // let paramValues = new ParamValues(resolvePath);
95
-
96
- // Attach bound resolveContext and paramValues to each node
97
- // Attach views to each node
98
- resolvePath . forEach ( ( node : Node ) => {
100
+ return resolvePath . map ( ( node : Node ) => {
99
101
node . resolveContext = resolveContext . isolateRootTo ( node . state ) ;
100
- node . resolves [ '$stateParams' ] = new Resolvable ( "$stateParams" , ( ) => node . paramValues , node . paramValues ) ;
102
+ return node ;
101
103
} ) ;
102
-
103
- return resolvePath ;
104
104
}
105
105
106
106
/**
@@ -123,33 +123,19 @@ export class PathFactory {
123
123
}
124
124
125
125
let from : Node [ ] , retained : Node [ ] , exiting : Node [ ] , entering : Node [ ] , to : Node [ ] ;
126
- // intermediate vars
127
- let retainedWithToParams : Node [ ] , enteringResolvePath : Node [ ] , toResolvePath : Node [ ] ;
128
126
129
127
from = fromPath ;
130
128
retained = from . slice ( 0 , keep ) ;
131
129
exiting = from . slice ( keep ) ;
132
130
133
131
// Create a new retained path (with shallow copies of nodes) which have the params of the toPath mapped
134
- retainedWithToParams = retained . map ( applyToParams ) ;
135
- enteringResolvePath = toPath . slice ( keep ) ;
136
- // "toResolvePath" is "retainedWithToParams" concat "enteringResolvePath".
137
- toResolvePath = ( retainedWithToParams ) . concat ( enteringResolvePath ) ;
138
-
139
- // "to: is "toResolvePath" with ParamValues/ResolveContext added to each node and bound to the path context
140
- to = PathFactory . bindTransNodesToPath ( toResolvePath ) ;
141
-
142
- // "entering" is the tail of "to"
143
- entering = to . slice ( keep ) ;
132
+ let retainedWithToParams = retained . map ( applyToParams ) ;
133
+ entering = toPath . slice ( keep ) ;
134
+ to = ( retainedWithToParams ) . concat ( entering ) ;
144
135
145
136
return { from, to, retained, exiting, entering } ;
146
137
}
147
138
148
- static bindTransitionResolve ( treeChanges : TreeChanges , transition : Transition ) {
149
- let rootNode = treeChanges . to [ 0 ] ;
150
- rootNode . resolves [ '$transition$' ] = new Resolvable ( '$transition$' , ( ) => transition , transition ) ;
151
- }
152
-
153
139
/**
154
140
* Find a subpath of a path that stops at the node for a given state
155
141
*
0 commit comments