Fix RBE payload changing downstream (needs cloning before storing)

This commit is contained in:
Dave Conway-Jones 2017-09-11 17:33:50 +01:00
parent 86ab73662b
commit e89861f4e3
No known key found for this signature in database
GPG Key ID: 81B04231572A9A2D
3 changed files with 6 additions and 6 deletions

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-rbe",
"version" : "0.1.11",
"version" : "0.1.12",
"description" : "A Node-RED node that provides report-by-exception (RBE) and deadband capability.",
"dependencies" : {
},

View File

@ -25,13 +25,13 @@ module.exports = function(RED) {
if (typeof(msg.payload) === "object") {
if (typeof(node.previous[t]) !== "object") { node.previous[t] = {}; }
if (!RED.util.compareObjects(msg.payload, node.previous[t])) {
node.previous[t] = msg.payload;
node.previous[t] = RED.util.cloneMessage(msg.payload);
if (doSend) { node.send(msg); }
}
}
else {
if (msg.payload !== node.previous[t]) {
node.previous[t] = msg.payload;
node.previous[t] = RED.util.cloneMessage(msg.payload);
if (doSend) { node.send(msg); }
}
}
@ -54,7 +54,7 @@ module.exports = function(RED) {
}
}
else if (Math.abs(n - node.previous[t]) > node.gap) {
if (this.func === "deadband" || this.func === "deadbandEq") {
if (this.func === "deadband") {
if (node.inout === "out") { node.previous[t] = n; }
node.send(msg);
}

View File

@ -118,7 +118,7 @@ describe('rbe node', function() {
msg.should.have.a.property("payload", 10);
}
else if (c == 3) {
msg.should.have.a.property("payload", 22);
msg.should.have.a.property("payload", 20);
done();
}
});
@ -129,7 +129,7 @@ describe('rbe node', function() {
n1.emit("input", {payload:8});
n1.emit("input", {payload:10});
n1.emit("input", {payload:15});
n1.emit("input", {payload:22});
n1.emit("input", {payload:20});
});
});