From 539ca8b84da7fcc358be7fcd3e1fa130cfb00179 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Fri, 29 Dec 2017 16:57:37 +0000 Subject: [PATCH] keep changes in this branch in sync with other trigger changes --- nodes/core/core/89-trigger.html | 2 +- nodes/core/core/89-trigger.js | 10 +++++++--- test/nodes/core/core/89-trigger_spec.js | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/nodes/core/core/89-trigger.html b/nodes/core/core/89-trigger.html index c3bb4f2f7..f90bda1a4 100644 --- a/nodes/core/core/89-trigger.html +++ b/nodes/core/core/89-trigger.html @@ -92,7 +92,7 @@

If set to a string type, the node supports the mustache template syntax.

If the node receives a message with a reset property, or a payload that matches that configured in the node, any timeout or repeat currently in - progress will be cleared and no message triggered. + progress will be cleared and no message triggered.

The node can be configured to resend a message at a regular interval until it is reset by a received message.

diff --git a/nodes/core/core/89-trigger.js b/nodes/core/core/89-trigger.js index 35b50b487..40681c9cc 100644 --- a/nodes/core/core/89-trigger.js +++ b/nodes/core/core/89-trigger.js @@ -104,6 +104,7 @@ module.exports = function(RED) { if (node.duration === 0) { node.topics[topic].tout = 0; } else if (node.loop === true) { + /* istanbul ignore else */ if (node.topics[topic].tout) { clearInterval(node.topics[topic].tout); } /* istanbul ignore else */ if (node.op1type !== "nul") { @@ -129,16 +130,19 @@ module.exports = function(RED) { } else if ((node.extend === "true" || node.extend === true) && (node.duration > 0)) { /* istanbul ignore else */ - if (node.topics[topic].tout) { clearTimeout(node.topics[topic].tout); } if (node.op2type === "payl") { node.topics[topic].m2 = RED.util.cloneMessage(msg.payload); } + /* istanbul ignore else */ + if (node.topics[topic].tout) { clearTimeout(node.topics[topic].tout); } node.topics[topic].tout = setTimeout(function() { if (node.op2type !== "nul") { var msg2 = RED.util.cloneMessage(msg); if (node.op2type === "flow" || node.op2type === "global") { node.topics[topic].m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg); } - msg2.payload = node.topics[topic].m2; - node.send(msg2); + if (node.topics[topic] !== undefined) { + msg2.payload = node.topics[topic].m2; + node.send(msg2); + } } delete node.topics[topic]; node.status({}); diff --git a/test/nodes/core/core/89-trigger_spec.js b/test/nodes/core/core/89-trigger_spec.js index 74ba19d16..53b13564a 100644 --- a/test/nodes/core/core/89-trigger_spec.js +++ b/test/nodes/core/core/89-trigger_spec.js @@ -282,7 +282,7 @@ describe('trigger node', function() { n1.emit("input", {payload:1,topic:"A"}); n1.emit("input", {payload:2,topic:"B"}); n1.emit("input", {payload:3,topic:"C"}); - setTimeout( function() { n1.emit("input", {payload:2,topic:"B"})}, 25 ); + setTimeout( function() { n1.emit("input", {payload:2,topic:"B"})}, 20 ); }); });