Skip to content

Commit c813abf

Browse files
refactor(Node): rename attrs to be more descriptive
1 parent 60defb7 commit c813abf

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

src/path/node.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {ViewConfig} from "../view/view";
99

1010
export class Node {
1111

12-
public schema: Param[];
13-
public values: { [key: string]: any };
12+
public paramSchema: Param[];
13+
public paramValues: { [key: string]: any };
1414
public resolves: any;
1515
public views: ViewConfig[];
1616
public resolveContext: ResolveContext;
@@ -19,10 +19,10 @@ export class Node {
1919
// Possibly extract this logic into an intermediary object that maps states to nodes
2020
constructor(public state: State, params: RawParams = {}, resolves: any = {}) {
2121
// Object.freeze(extend(this, { ... }))
22-
this.schema = state.parameters({ inherit: false });
22+
this.paramSchema = state.parameters({ inherit: false });
2323

2424
const getParamVal = (paramDef: Param) => [ paramDef.id, paramDef.value(params[paramDef.id]) ];
25-
this.values = this.schema.reduce((memo, pDef) => applyPairs(memo, getParamVal(pDef)), {});
25+
this.paramValues = this.paramSchema.reduce((memo, pDef) => applyPairs(memo, getParamVal(pDef)), {});
2626

2727
this.resolves = extend(map(state.resolve, (fn: Function, name: string) => new Resolvable(name, fn)), resolves);
2828

@@ -32,16 +32,16 @@ export class Node {
3232
}
3333

3434
parameter(name: string): Param {
35-
return find(this.schema, propEq("id", name));
35+
return find(this.paramSchema, propEq("id", name));
3636
}
3737

38-
equals(node: Node, keys = this.schema.map(prop('id'))): boolean {
39-
const paramValsEq = key => this.parameter(key).type.equals(this.values[key], node.values[key]);
38+
equals(node: Node, keys = this.paramSchema.map(prop('id'))): boolean {
39+
const paramValsEq = key => this.parameter(key).type.equals(this.paramValues[key], node.paramValues[key]);
4040
return this.state === node.state && keys.map(paramValsEq).reduce(allTrueR, true);
4141
}
4242

4343
static clone(node: Node, update: any = {}) {
44-
return new Node(node.state, (update.values || node.values), (update.resolves || node.resolves));
44+
return new Node(node.state, (update.paramValues || node.paramValues), (update.resolves || node.resolves));
4545
}
4646

4747
/**

src/path/pathFactory.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export class PathFactory {
2121
/** Given a Node[], create an TargetState */
2222
static makeTargetState(path: Node[]): TargetState {
2323
let state = tail(path).state;
24-
return new TargetState(state, state, path.map(prop("values")).reduce(mergeR, {}));
24+
return new TargetState(state, state, path.map(prop("paramValues")).reduce(mergeR, {}));
2525
}
2626

2727
/* Given params and a state, creates an Node */
@@ -50,8 +50,8 @@ export class PathFactory {
5050
*/
5151
static inheritParams(fromPath: Node[], toPath: Node[], toKeys: string[] = []): Node[] {
5252
function nodeParamVals(path: Node[], state: State): RawParams {
53-
let node = find(path, propEq('state', state));
54-
return extend({}, node && node.values);
53+
let node: Node = find(path, propEq('state', state));
54+
return extend({}, node && node.paramValues);
5555
}
5656

5757
/**
@@ -60,7 +60,7 @@ export class PathFactory {
6060
*/
6161
let makeInheritedParamsNode = curry(function(_fromPath: Node[], _toKeys: string[], toNode: Node): Node {
6262
// All param values for the node (may include default key/vals, when key was not found in toParams)
63-
let toParamVals = extend({}, toNode && toNode.values);
63+
let toParamVals = extend({}, toNode && toNode.paramValues);
6464
// limited to only those keys found in toParams
6565
let incomingParamVals = pick(toParamVals, _toKeys);
6666
toParamVals = omit(toParamVals, _toKeys);
@@ -88,7 +88,7 @@ export class PathFactory {
8888
resolvePath.forEach((node: Node) => {
8989
node.resolveContext = resolveContext.isolateRootTo(node.state);
9090
node.resolveInjector = new ResolveInjector(node.resolveContext, node.state);
91-
node.resolves.$stateParams = new Resolvable("$stateParams", () => node.values, node.values);
91+
node.resolves.$stateParams = new Resolvable("$stateParams", () => node.paramValues, node.paramValues);
9292
});
9393

9494
return resolvePath;
@@ -108,7 +108,7 @@ export class PathFactory {
108108

109109
/** Given a retained node, return a new node which uses the to node's param values */
110110
function applyToParams(retainedNode: Node, idx: number): Node {
111-
return Node.clone(retainedNode, { values: toPath[idx].values });
111+
return Node.clone(retainedNode, { paramValues: toPath[idx].paramValues });
112112
}
113113

114114
let from: Node[], retained: Node[], exiting: Node[], entering: Node[], to: Node[];

src/transition/transition.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export class Transition implements IHookRegistry {
179179
* @returns transition parameter values for the desired path.
180180
*/
181181
params(pathname: string = "to"): { [key: string]: any } {
182-
return this._treeChanges[pathname].map(prop("values")).reduce(mergeR, {});
182+
return this._treeChanges[pathname].map(prop("paramValues")).reduce(mergeR, {});
183183
}
184184

185185
/**
@@ -311,8 +311,8 @@ export class Transition implements IHookRegistry {
311311
let {to, from} = this._treeChanges;
312312
if (this._options.reload || tail(to).state !== tail(from).state) return false;
313313

314-
let nodeSchemas: Param[][] = to.map(node => node.schema.filter(not(prop('dynamic'))));
315-
let [toValues, fromValues] = [to, from].map(path => path.map(prop('values')));
314+
let nodeSchemas: Param[][] = to.map((node: Node) => node.paramSchema.filter(not(prop('dynamic'))));
315+
let [toValues, fromValues] = [to, from].map(path => path.map(prop('paramValues')));
316316
let tuples = arrayTuples(nodeSchemas, toValues, fromValues);
317317

318318
return tuples.map(([schema, toVals, fromVals]) => Param.equals(schema, toVals, fromVals)).reduce(allTrueR, true);
@@ -426,7 +426,7 @@ export class Transition implements IHookRegistry {
426426
// (X) means the to state is invalid.
427427
let id = this.$id,
428428
from = isObject(fromStateOrName) ? fromStateOrName.name : fromStateOrName,
429-
fromParams = toJson(avoidEmptyHash(this._treeChanges.from.map(prop('values')).reduce(mergeR, {}))),
429+
fromParams = toJson(avoidEmptyHash(this._treeChanges.from.map(prop('paramValues')).reduce(mergeR, {}))),
430430
toValid = this.valid() ? "" : "(X) ",
431431
to = isObject(toStateOrName) ? toStateOrName.name : toStateOrName,
432432
toParams = toJson(avoidEmptyHash(this.params()));

0 commit comments

Comments
 (0)