Skip to content

Commit 41408d5

Browse files
committed
Add symbols to identify entity types
1 parent d3b7137 commit 41408d5

File tree

9 files changed

+37
-6
lines changed

9 files changed

+37
-6
lines changed

lib/NRConfigNode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const NRObject = require("./NRObject.js");
2+
const Symbols = require("./Symbols");
23

34
/**
45
* NRConfigNode - Description
@@ -15,6 +16,7 @@ class NRConfigNode extends NRObject {
1516
*/
1617
constructor(config) {
1718
super(config);
19+
this.TYPE = Symbols.ConfigNode;
1820
this.users = new Set();
1921
}
2022

lib/NRFlow.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const NRContainer = require("./NRContainer.js");
2-
2+
const Symbols = require("./Symbols");
33

44
/**
55
* NRFlow - Description
@@ -17,6 +17,7 @@ class NRFlow extends NRContainer {
1717
*/
1818
constructor(config) {
1919
super(config);
20+
this.TYPE = Symbols.Flow;
2021
this.disabled = !!config.disabled;
2122
this.info = config.info;
2223

lib/NRGroup.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const NRContainer = require("./NRContainer.js");
2+
const Symbols = require("./Symbols");
23

34
/**
45
* NRGroup - Description
@@ -14,6 +15,7 @@ class NRGroup extends NRContainer {
1415
*/
1516
constructor(config) {
1617
super(config);
18+
this.TYPE = Symbols.Group;
1719
this.w = config.w;
1820
this.h = config.h;
1921
this.groupId = config.g;
@@ -37,7 +39,7 @@ class NRGroup extends NRContainer {
3739
this.nodes.set(node.id, node);
3840
node.setGroup(this);
3941
}
40-
42+
4143
export() {
4244
let obj = super.export();
4345
if (this.groupId) {

lib/NRNode.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const NRObject = require("./NRObject.js");
2+
const Symbols = require("./Symbols");
23

34
/**
45
* NRNode - Description
@@ -22,6 +23,7 @@ class NRNode extends NRObject {
2223
*/
2324
constructor(config) {
2425
super(config);
26+
this.TYPE = Symbols.Node;
2527
this.x = config.x;
2628
this.y = config.y;
2729
this.groupId = config.g;

lib/NRSubflow.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const NRFlow = require("./NRFlow.js");
2+
const Symbols = require("./Symbols");
23

34
/**
45
* NRSubflow - Description
@@ -14,6 +15,8 @@ class NRSubflow extends NRFlow {
1415
*/
1516
constructor(config) {
1617
super(config);
18+
this.TYPE = Symbols.Subflow;
19+
1720
this.instances = new Map();
1821
this._ownProperties = ["category", "in", "out", "env", "meta", "color", "inputLabels", "outputLabels", "icon"];
1922
this._ownProperties.forEach(prop => {

lib/NRWire.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const Symbols = require("./Symbols");
2+
13
/**
24
* NRWire - Description
35
* @property {NRNode} sourceNode - source of the wire

lib/Symbols.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
Node: Symbol("NRNode"),
3+
ConfigNode: Symbol("NRConfigNode"),
4+
Group: Symbol("NRGroup"),
5+
Flow: Symbol("NRFlow"),
6+
Subflow: Symbol("NRSubflow")
7+
}

lib/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ function parseFlow(flowConfig) {
1212
}
1313

1414
module.exports = {
15-
parseFlow: parseFlow
15+
parseFlow: parseFlow,
16+
types: require("./Symbols")
1617
}

test/test.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const fs = require("fs");
12
const assert = require("assert");
23
const fp = require("../lib/index.js");
34

@@ -10,13 +11,23 @@ describe("Flow Parser tests", function() {
1011
})
1112

1213
function runTests(filename) {
13-
const fs = require("fs");
14-
15-
1614
const original = JSON.parse(fs.readFileSync(filename,"utf-8"));
1715
const flowSet = fp.parseFlow(original);
1816
const generated = flowSet.export();
1917

18+
// 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)
29+
// }
30+
// })
2031

2132
const knownIds = original.map(n => n.id).sort();
2233

0 commit comments

Comments
 (0)