Skip to content

Commit 99e07b2

Browse files
refactor(Node): rename Node to PathNode (to avoid conflicts with browser DOM Node class
1 parent b8e7912 commit 99e07b2

24 files changed

+151
-128
lines changed

src/ng1/directives/viewDirective.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {TransitionService} from "../../transition/transitionService";
99
import {parse} from "../../common/hof";
1010
import {ResolveContext} from "../../resolve/resolveContext";
1111
import {Transition} from "../../transition/transition";
12-
import {Node} from "../../path/node";
12+
import {PathNode} from "../../path/node";
1313
import {Param} from "../../params/param";
1414
import {kebobString} from "../../common/strings";
1515
import {HookRegOptions} from "../../transition/interface";
@@ -401,8 +401,8 @@ function registerControllerCallbacks($transitions: TransitionService, controller
401401

402402
let toParams = $transition$.params("to");
403403
let fromParams = $transition$.params("from");
404-
let toSchema: Param[] = $transition$.treeChanges().to.map((node: Node) => node.paramSchema).reduce(unnestR, []);
405-
let fromSchema: Param[] = $transition$.treeChanges().from.map((node: Node) => node.paramSchema).reduce(unnestR, []);
404+
let toSchema: Param[] = $transition$.treeChanges().to.map((node: PathNode) => node.paramSchema).reduce(unnestR, []);
405+
let fromSchema: Param[] = $transition$.treeChanges().from.map((node: PathNode) => node.paramSchema).reduce(unnestR, []);
406406

407407
// Find the to params that have different values than the from params
408408
let changedToParams = toSchema.filter((param: Param) => {

src/ng1/legacy/resolveService.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {State} from "../../state/stateObject";
2-
import {Node} from "../../path/node";
2+
import {PathNode} from "../../path/node";
33
import {ResolveContext} from "../../resolve/resolveContext";
44
import {Resolvable} from "../../resolve/resolvable";
55
import {map} from "../../common/common";
@@ -12,8 +12,8 @@ export const resolveFactory = () => ({
1212
* @param parent a promise for a "parent resolve"
1313
*/
1414
resolve: (invocables, locals = {}, parent?) => {
15-
let parentNode = new Node(new State(<any> { params: {} }));
16-
let node = new Node(new State(<any> { params: {} }));
15+
let parentNode = new PathNode(new State(<any> { params: {} }));
16+
let node = new PathNode(new State(<any> { params: {} }));
1717
let context = new ResolveContext([parentNode, node]);
1818

1919
context.addResolvables(Resolvable.makeResolvables(invocables), node.state);

src/ng1/services.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {services} from "../common/coreservices";
1515
import {map, bindFunctions, removeFrom, find, noop} from "../common/common";
1616
import {prop, propEq} from "../common/hof";
1717
import {isObject} from "../common/predicates";
18-
import {Node} from "../path/node";
18+
import {PathNode} from "../path/node";
1919
import {resolveFactory} from "./legacy/resolveService";
2020
import {trace} from "../common/trace";
2121
import {ng1ViewsBuilder, ng1ViewConfigFactory, Ng1ViewConfig} from "./statebuilders/views";
@@ -260,7 +260,7 @@ function getTransitionsProvider() {
260260
// TODO: check if we can remove loadAllControllerLocals. Shouldn't be necessary without JIT resolve policy
261261
function loadAllControllerLocals($transition$: Transition) {
262262
const loadLocals = (vc: Ng1ViewConfig) => {
263-
let node = (<Node> find($transition$.treeChanges().to, propEq('state', vc.viewDecl.$context)));
263+
let node = (<PathNode> find($transition$.treeChanges().to, propEq('state', vc.viewDecl.$context)));
264264
// Temporary fix; This whole callback should be nuked when fixing #2662
265265
if (!node) return services.$q.when();
266266
let resolveCtx = node.resolveContext;

src/ng1/statebuilders/views.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {ViewService} from "../../view/view";
88
import {isInjectable, isDefined, isString, isObject} from "../../common/predicates";
99
import {services} from "../../common/coreservices";
1010
import {trace} from "../../common/trace";
11-
import {Node} from "../../path/node";
11+
import {PathNode} from "../../path/node";
1212
import {TemplateFactory} from "../templateFactory";
1313
import {ResolveContext} from "../../resolve/resolveContext";
1414

@@ -104,7 +104,7 @@ export class Ng1ViewConfig implements ViewConfig {
104104
template: string;
105105
locals: any; // TODO: delete me
106106

107-
constructor(public node: Node, public viewDecl: Ng1ViewDeclaration) { }
107+
constructor(public node: PathNode, public viewDecl: Ng1ViewDeclaration) { }
108108

109109
load() {
110110
let $q = services.$q;

src/ng2/directives/uiSrefStatus.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import {Directive, Output, EventEmitter} from "@angular/core";
33
import {StateService} from "../../state/stateService";
44
import {UiSref} from "./uiSref";
5-
import {Node} from "../../path/node";
5+
import {PathNode} from "../../path/node";
66
import {TransitionService} from "../../transition/transitionService";
77
import {Transition} from "../../transition/transition";
88
import {TargetState} from "../../state/targetState";
@@ -95,18 +95,18 @@ export class UiSrefStatus {
9595

9696

9797
/**
98-
* Returns a Predicate<Node[]> that returns true when the target state (and any param values)
98+
* Returns a Predicate<PathNode[]> that returns true when the target state (and any param values)
9999
* match the (tail of) the path, and the path's param values
100100
*/
101101
const pathMatches = (target: TargetState) => {
102102
let state: State = target.$state();
103103
let targetParamVals = target.params();
104-
let targetPath: Node[] = PathFactory.buildPath(target);
104+
let targetPath: PathNode[] = PathFactory.buildPath(target);
105105
let paramSchema: Param[] = targetPath.map(node => node.paramSchema)
106106
.reduce(unnestR, [])
107107
.filter((param: Param) => targetParamVals.hasOwnProperty(param.id));
108108

109-
return (path: Node[]) => {
109+
return (path: PathNode[]) => {
110110
let tailNode = tail(path);
111111
if (!tailNode || tailNode.state !== state) return false;
112112
var paramValues = PathFactory.paramValues(path);
@@ -121,7 +121,7 @@ export class UiSrefStatus {
121121
* Expands the path to [c], [c, d]
122122
* Then appends each to [a,b,] and returns: [a, b, c], [a, b, c, d]
123123
*/
124-
function spreadToSubPaths (path: Node[], appendTo: Node[] = []): Node[][] {
124+
function spreadToSubPaths (path: PathNode[], appendTo: PathNode[] = []): PathNode[][] {
125125
return path.map(node => appendTo.concat(PathFactory.subPath(path, node.state)));
126126
}
127127

@@ -135,7 +135,7 @@ export class UiSrefStatus {
135135
this._setStatus(status);
136136
}
137137

138-
let update = (currentPath: Node[]) => () => {
138+
let update = (currentPath: PathNode[]) => () => {
139139
if (this._deregisterHook == null) return; // destroyed
140140
if (!$transition$.isActive()) return; // superseded
141141
status.active = spreadToSubPaths(currentPath).map(isTarget).reduce(anyTrueR, false);

src/ng2/providers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
*/ /** */
4949
import {Provider, provide} from "@angular/core";
5050
import {UIRouter} from "../router";
51-
import {Node} from "../path/node";
51+
import {PathNode} from "../path/node";
5252
import {StateRegistry} from "../state/stateRegistry";
5353
import {StateService} from "../state/stateService";
5454
import {TransitionService} from "../transition/transitionService";
@@ -67,7 +67,7 @@ let uiRouterFactory = (routerConfig: UIRouterConfig, location: UIRouterLocation)
6767

6868
location.init();
6969

70-
router.viewService.viewConfigFactory("ng2", (node: Node, config: Ng2ViewDeclaration) => new Ng2ViewConfig(node, config));
70+
router.viewService.viewConfigFactory("ng2", (node: PathNode, config: Ng2ViewDeclaration) => new Ng2ViewConfig(node, config));
7171
router.stateRegistry.decorator('views', ng2ViewsBuilder);
7272

7373
router.stateRegistry.stateQueue.autoFlush(router.stateService);

src/ng2/statebuilders/views.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/** @module ng2 */ /** */
22
import {State} from "../../state/stateObject";
3-
import {Node} from "../../path/node";
3+
import {PathNode} from "../../path/node";
44
import {pick, forEach} from "../../common/common";
55
import {ViewConfig} from "../../view/interface";
66
import {Ng2ViewDeclaration} from "../interface";
@@ -39,7 +39,7 @@ export function ng2ViewsBuilder(state: State) {
3939
export class Ng2ViewConfig implements ViewConfig {
4040
loaded: boolean = true;
4141

42-
constructor(public node: Node, public viewDecl: Ng2ViewDeclaration) { }
42+
constructor(public node: PathNode, public viewDecl: Ng2ViewDeclaration) { }
4343

4444
load() {
4545
return services.$q.when(this);

src/path/node.ts

+35-13
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,34 @@ import {Resolvable} from "../resolve/resolvable";
88
import {ResolveContext} from "../resolve/resolveContext";
99
import {ViewConfig} from "../view/interface";
1010

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 */
1220
public state: State;
21+
/** The parameters declared on the state */
1322
public paramSchema: Param[];
23+
/** The parameter values that belong to the state */
1424
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 */
1528
public resolvables: Resolvable[];
29+
/** The state's declared view configuration objects */
1630
public views: ViewConfig[];
17-
public resolveContext: ResolveContext;
1831

19-
constructor(state: Node);
32+
/** Creates a copy of a PathNode */
33+
constructor(state: PathNode);
34+
/** Creates a new (empty) PathNode for a State */
2035
constructor(state: State);
2136
constructor(state) {
22-
if (state instanceof Node) {
23-
let node: Node = state;
37+
if (state instanceof PathNode) {
38+
let node: PathNode = state;
2439
this.state = node.state;
2540
this.paramSchema = node.paramSchema.slice();
2641
this.paramValues = extend({}, node.paramValues);
@@ -35,23 +50,30 @@ export class Node {
3550
}
3651
}
3752

38-
applyRawParams(params: RawParams): Node {
53+
/** Sets [[paramValues]] for the node, from the values of an object hash */
54+
applyRawParams(params: RawParams): PathNode {
3955
const getParamVal = (paramDef: Param) => [ paramDef.id, paramDef.value(params[paramDef.id]) ];
4056
this.paramValues = this.paramSchema.reduce((memo, pDef) => applyPairs(memo, getParamVal(pDef)), {});
4157
return this;
4258
}
4359

60+
/** Gets a specific [[Param]] metadata that belongs to the node */
4461
parameter(name: string): Param {
4562
return find(this.paramSchema, propEq("id", name));
4663
}
4764

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 {
4970
const paramValsEq = key => this.parameter(key).type.equals(this.paramValues[key], node.paramValues[key]);
5071
return this.state === node.state && keys.map(paramValsEq).reduce(allTrueR, true);
5172
}
5273

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);
5577
}
5678

5779
/**
@@ -60,17 +82,17 @@ export class Node {
6082
* The new path starts from root and contains any nodes that match the nodes in the second path.
6183
* Nodes are compared using their state property and parameter values.
6284
*/
63-
static matching(pathA: Node[], pathB: Node[]): Node[] {
85+
static matching(pathA: PathNode[], pathB: PathNode[]): PathNode[] {
6486
let matching = [];
65-
87+
6688
for (let i = 0; i < pathA.length && i < pathB.length; i++) {
6789
let a = pathA[i], b = pathB[i];
68-
90+
6991
if (a.state !== b.state) break;
7092
if (!Param.equals(a.paramSchema, a.paramValues, b.paramValues)) break;
7193
matching.push(a);
7294
}
73-
95+
7496
return matching
7597
}
7698
}

0 commit comments

Comments
 (0)