From fee6881f1b9847ca68602022871ccfcf2141ea39 Mon Sep 17 00:00:00 2001 From: "p.vanderwilt" Date: Fri, 4 Jul 2025 12:06:58 +0200 Subject: [PATCH] Refactor nodeClass for to mostly allign with the standard EVOLV structure --- src/nodeClass.js | 78 ++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 35 deletions(-) diff --git a/src/nodeClass.js b/src/nodeClass.js index 9281a45..ad11f69 100644 --- a/src/nodeClass.js +++ b/src/nodeClass.js @@ -15,6 +15,48 @@ class nodeClass { this.RED = RED; this.name = nameOfNode; + this._setupClass(uiConfig, this.node); + + this._attachInputHandler(); + + } + + _attachInputHandler() { // Handle input messages + this.node.on('input', function(msg, send, done) { + let toggleUpdate = false; + + switch (msg.topic) { + case "clock": + toggleUpdate = true; + break; + case "Fluent": + this.reactor.setInfluent = msg; + if (msg.payload.inlet == 0) { + toggleUpdate = true; + } + break; + case "OTR": + this.reactor.setOTR = msg; + break; + case "Dispersion": + this.reactor.setDispersion = msg; + break; + default: + console.log("Unknown topic: " + msg.topic); + } + + if (toggleUpdate) { + this.reactor.updateState(msg.timestamp); + send(this.reactor.getEffluent); + } + + if (done) { + done(); + } + }); + } + + _setupClass(uiConfig, node) { let new_reactor; switch (uiConfig.reactor_type) { @@ -68,42 +110,8 @@ class nodeClass { console.warn("Unknown reactor type: " + uiConfig.reactor_type); } - const reactor = new_reactor; // protect from reassignment - - this.node.on('input', function(msg, send, done) { - let toggleUpdate = false; - - switch (msg.topic) { - case "clock": - toggleUpdate = true; - break; - case "Fluent": - reactor.setInfluent = msg; - if (msg.payload.inlet == 0) { - toggleUpdate = true; - } - break; - case "OTR": - reactor.setOTR = msg; - break; - case "Dispersion": - reactor.setDispersion = msg; - break; - default: - console.log("Unknown topic: " + msg.topic); - } - - if (toggleUpdate) { - reactor.updateState(msg.timestamp); - send(reactor.getEffluent); - } - - if (done) { - done(); - } - }); + node.reactor = new_reactor; // protect from reassignment } - } module.exports = nodeClass; \ No newline at end of file