Refactor Subflow logic into own class

This commit is contained in:
Nick O'Leary
2019-01-16 16:27:19 +00:00
parent da756fa568
commit 81f4e0de56
9 changed files with 1214 additions and 1155 deletions

View File

@@ -35,6 +35,9 @@ function Node(n) {
if (n._alias) {
this._alias = n._alias;
}
if (n._flow) {
this._flow = n._flow;
}
this.updateWires(n.wires);
}
@@ -131,10 +134,12 @@ Node.prototype.send = function(msg) {
msg._msgid = redUtil.generateId();
}
this.metric("send",msg);
node = flows.get(this._wire);
node = this._flow.getNode(this._wire);
/* istanbul ignore else */
if (node) {
node.receive(msg);
} else {
console.log("trying to send to a node not on this flow",this._wire);
}
return;
} else {
@@ -163,7 +168,7 @@ Node.prototype.send = function(msg) {
var k = 0;
// for each recipent node of that output
for (var j = 0; j < wires.length; j++) {
node = flows.get(wires[j]); // node at end of wire j
node = this._flow.getNode(wires[j]); // node at end of wire j
if (node) {
// for each msg to send eg. [[m1, m2, ...], ...]
for (k = 0; k < msgs.length; k++) {
@@ -182,6 +187,8 @@ Node.prototype.send = function(msg) {
}
}
}
} else {
console.log("trying to send to a node not on this flow",this._wire);
}
}
}
@@ -251,7 +258,7 @@ Node.prototype.error = function(logMessage,msg) {
}
var handled = false;
if (msg) {
handled = flows.handleError(this,logMessage,msg);
handled = this._flow.handleError(this,logMessage,msg);
}
if (!handled) {
log_helper(this, Log.ERROR, logMessage);
@@ -286,6 +293,6 @@ Node.prototype.metric = function(eventname, msg, metricValue) {
* status: { fill:"red|green", shape:"dot|ring", text:"blah" }
*/
Node.prototype.status = function(status) {
flows.handleStatus(this,status);
this._flow.handleStatus(this,status);
};
module.exports = Node;