Skip to content

Commit 4ee4726

Browse files
committed
Ensure flow walk order visits nodes last
This ensures any containing groups have been visited and are known before the individual nodes are visited
1 parent c82ae57 commit 4ee4726

File tree

6 files changed

+34
-22
lines changed

6 files changed

+34
-22
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ The `walk` function can be used to invoke a function on every object in the flow
2626
configuration in a reasonably well-defined order:
2727

2828
- Subflow definitions
29-
- Nodes
3029
- Config nodes scoped to this subflow
3130
- Groups
31+
- Nodes
3232
- Global Config nodes
3333
- Flows
34-
- Nodes
3534
- Config nodes scoped to this flow
3635
- Groups
36+
- Nodes
3737

3838
```
3939
const fs = require("fs");

lib/NRContainer.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ class NRContainer extends NRObject {
3333
return result;
3434
}
3535

36-
walk(callback) {
37-
super.walk(callback);
38-
this.nodes.forEach(n => n.walk(callback))
36+
walkContents(callback) {
37+
this.nodes.forEach(n => n.walk(callback));
3938
}
4039
}
4140

lib/NRFlow.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class NRFlow extends NRContainer {
8484
this.subflows.forEach(n => n.walk(callback))
8585
this.configs.forEach(n => n.walk(callback))
8686
this.groups.forEach(n => n.walk(callback))
87+
super.walkContents(callback);
8788
}
8889
}
8990
module.exports = NRFlow;

lib/NRGroup.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,6 @@ class NRGroup extends NRContainer {
5959
// export this contents this way.
6060
return [];
6161
}
62-
63-
walk(callback) {
64-
// Don't use super.walk as that will revisit this.nodes
65-
callback(this);
66-
}
6762
}
6863

6964
module.exports = NRGroup

lib/NRObject.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ class NRObject {
6565
callback(this);
6666
}
6767
}
68+
69+
walkContents(callback) {
70+
71+
}
6872
}
6973

7074
module.exports = NRObject;

test/test.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const fs = require("fs");
22
const assert = require("assert");
3-
const fp = require("../lib/index.js");
3+
const FlowParser = require("../lib/index.js");
44

55
describe("Flow Parser tests", function() {
66
it('passes flow 1', function() {
@@ -12,20 +12,33 @@ describe("Flow Parser tests", function() {
1212

1313
function runTests(filename) {
1414
const original = JSON.parse(fs.readFileSync(filename,"utf-8"));
15-
const flowSet = fp.parseFlow(original);
15+
const flowSet = FlowParser.parseFlow(original);
1616
const generated = flowSet.export();
1717

18+
19+
1820
// flowSet.walk(function(obj) {
19-
// if (obj.type === 'tab') {
20-
// console.log("FLOW",obj.type)
21-
// } else if (obj.type === 'subflow') {
22-
// console.log("SUBFLOW",obj.type)
23-
// } else if (obj.type === 'group') {
24-
// console.log("GROUP",obj.type)
25-
// } else if (obj.constructor.name === 'NRConfigNode') {
26-
// console.log("CONFIG NODE",obj.type)
27-
// } else {
28-
// console.log("NODE",obj.type)
21+
// switch(obj.TYPE) {
22+
// case FlowParser.types.Flow:
23+
// // A flow object
24+
// console.log("FLOW",obj.id)
25+
// break;
26+
// case FlowParser.types.Subflow:
27+
// // A subflow definition
28+
// console.log("SUBFLOW",obj.id)
29+
// break;
30+
// case FlowParser.types.Group:
31+
// // A group object
32+
// console.log(" Group",obj.id)
33+
// break;
34+
// case FlowParser.types.ConfigNode:
35+
// // A config node
36+
// console.log(" ConfigNode",obj.id)
37+
// break;
38+
// case FlowParser.types.Node:
39+
// // A flow node
40+
// console.log(" Node",obj.id)
41+
// break;
2942
// }
3043
// })
3144

0 commit comments

Comments
 (0)