11/** @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" ;
33import { prop , propEq } from "../common/hof" ;
44import { State } from "../state/module" ;
55import { RawParams } from "../params/interface" ;
@@ -9,22 +9,38 @@ import {ViewConfig} from "../view/interface";
99import { Resolvables } from "../resolve/interface" ;
1010
1111export class Node {
12+ public state : State ;
1213 public paramSchema : Param [ ] ;
1314 public paramValues : { [ key : string ] : any } ;
1415 public resolves : Resolvables ;
1516 public views : ViewConfig [ ] ;
1617 public resolveContext : ResolveContext ;
1718 public resolveInjector : ResolveInjector ;
1819
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+ }
2339
40+ applyRawParams ( params : RawParams ) : Node {
2441 const getParamVal = ( paramDef : Param ) => [ paramDef . id , paramDef . value ( params [ paramDef . id ] ) ] ;
2542 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 ;
2844 }
2945
3046 parameter ( name : string ) : Param {
@@ -36,8 +52,8 @@ export class Node {
3652 return this . state === node . state && keys . map ( paramValsEq ) . reduce ( allTrueR , true ) ;
3753 }
3854
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 ) ;
4157 }
4258
4359 /**
0 commit comments