1
1
/** @module path */ /** for typedoc */
2
- import { extend , applyPairs , map , find , allTrueR , values } from "../common/common" ;
2
+ import { extend , applyPairs , map , find , allTrueR , values , mapObj } from "../common/common" ;
3
3
import { prop , propEq } from "../common/hof" ;
4
4
import { State } from "../state/module" ;
5
5
import { RawParams } from "../params/interface" ;
@@ -9,22 +9,38 @@ import {ViewConfig} from "../view/interface";
9
9
import { Resolvables } from "../resolve/interface" ;
10
10
11
11
export class Node {
12
+ public state : State ;
12
13
public paramSchema : Param [ ] ;
13
14
public paramValues : { [ key : string ] : any } ;
14
15
public resolves : Resolvables ;
15
16
public views : ViewConfig [ ] ;
16
17
public resolveContext : ResolveContext ;
17
18
public resolveInjector : ResolveInjector ;
18
19
19
- // Possibly extract this logic into an intermediary object that maps states to nodes
20
- constructor ( public state : State , params : RawParams = { } , resolvables : Resolvables = { } ) {
21
- // Object.freeze(extend(this, { ... }))
22
- this . paramSchema = state . parameters ( { inherit : false } ) ;
20
+ constructor ( state : Node ) ;
21
+ constructor ( state : State ) ;
22
+ constructor ( state ) {
23
+ if ( state instanceof Node ) {
24
+ let node : Node = state ;
25
+ this . state = node . state ;
26
+ this . paramSchema = node . paramSchema . slice ( ) ;
27
+ this . paramValues = extend ( { } , node . paramValues ) ;
28
+ this . resolves = extend ( { } , node . resolves ) ;
29
+ this . views = node . views && node . views . slice ( ) ;
30
+ this . resolveContext = node . resolveContext ;
31
+ this . resolveInjector = node . resolveInjector ;
32
+ } else {
33
+ this . state = state ;
34
+ this . paramSchema = state . parameters ( { inherit : false } ) ;
35
+ this . paramValues = { } ;
36
+ this . resolves = mapObj ( state . resolve , ( fn : Function , name : string ) => new Resolvable ( name , fn ) ) ;
37
+ }
38
+ }
23
39
40
+ applyRawParams ( params : RawParams ) : Node {
24
41
const getParamVal = ( paramDef : Param ) => [ paramDef . id , paramDef . value ( params [ paramDef . id ] ) ] ;
25
42
this . paramValues = this . paramSchema . reduce ( ( memo , pDef ) => applyPairs ( memo , getParamVal ( pDef ) ) , { } ) ;
26
-
27
- this . resolves = extend ( map ( state . resolve , ( fn : Function , name : string ) => new Resolvable ( name , fn ) ) , resolvables ) ;
43
+ return this ;
28
44
}
29
45
30
46
parameter ( name : string ) : Param {
@@ -36,8 +52,8 @@ export class Node {
36
52
return this . state === node . state && keys . map ( paramValsEq ) . reduce ( allTrueR , true ) ;
37
53
}
38
54
39
- static clone ( node : Node , update : any = { } ) {
40
- return new Node ( node . state , ( update . paramValues || node . paramValues ) , ( update . resolves || node . resolves ) ) ;
55
+ static clone ( node : Node ) {
56
+ return new Node ( node ) ;
41
57
}
42
58
43
59
/**
0 commit comments