1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.PathNode = void 0;
|
4 | var common_1 = require("../common/common");
|
5 | var hof_1 = require("../common/hof");
|
6 | var param_1 = require("../params/param");
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | var PathNode = (function () {
|
15 | function PathNode(stateOrNode) {
|
16 | if (stateOrNode instanceof PathNode) {
|
17 | var node = stateOrNode;
|
18 | this.state = node.state;
|
19 | this.paramSchema = node.paramSchema.slice();
|
20 | this.paramValues = common_1.extend({}, node.paramValues);
|
21 | this.resolvables = node.resolvables.slice();
|
22 | this.views = node.views && node.views.slice();
|
23 | }
|
24 | else {
|
25 | var state = stateOrNode;
|
26 | this.state = state;
|
27 | this.paramSchema = state.parameters({ inherit: false });
|
28 | this.paramValues = {};
|
29 | this.resolvables = state.resolvables.map(function (res) { return res.clone(); });
|
30 | }
|
31 | }
|
32 | PathNode.prototype.clone = function () {
|
33 | return new PathNode(this);
|
34 | };
|
35 |
|
36 | PathNode.prototype.applyRawParams = function (params) {
|
37 | var getParamVal = function (paramDef) { return [paramDef.id, paramDef.value(params[paramDef.id])]; };
|
38 | this.paramValues = this.paramSchema.reduce(function (memo, pDef) { return common_1.applyPairs(memo, getParamVal(pDef)); }, {});
|
39 | return this;
|
40 | };
|
41 |
|
42 | PathNode.prototype.parameter = function (name) {
|
43 | return common_1.find(this.paramSchema, hof_1.propEq('id', name));
|
44 | };
|
45 | |
46 |
|
47 |
|
48 |
|
49 | PathNode.prototype.equals = function (node, paramsFn) {
|
50 | var diff = this.diff(node, paramsFn);
|
51 | return diff && diff.length === 0;
|
52 | };
|
53 | |
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | PathNode.prototype.diff = function (node, paramsFn) {
|
66 | if (this.state !== node.state)
|
67 | return false;
|
68 | var params = paramsFn ? paramsFn(this) : this.paramSchema;
|
69 | return param_1.Param.changed(params, this.paramValues, node.paramValues);
|
70 | };
|
71 | |
72 |
|
73 |
|
74 |
|
75 | PathNode.clone = function (node) { return node.clone(); };
|
76 | return PathNode;
|
77 | }());
|
78 | exports.PathNode = PathNode;
|
79 |
|
\ | No newline at end of file |