1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

keep changes in this branch in sync with other trigger changes

This commit is contained in:
Dave Conway-Jones 2017-12-29 16:57:37 +00:00
parent 813a5d2879
commit 539ca8b84d
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
3 changed files with 9 additions and 5 deletions

View File

@ -92,7 +92,7 @@
<p>If set to a <i>string</i> type, the node supports the mustache template syntax.</p> <p>If set to a <i>string</i> type, the node supports the mustache template syntax.</p>
<p>If the node receives a message with a <code>reset</code> property, or a <code>payload</code> <p>If the node receives a message with a <code>reset</code> property, or a <code>payload</code>
that matches that configured in the node, any timeout or repeat currently in that matches that configured in the node, any timeout or repeat currently in
progress will be cleared and no message triggered.</o> progress will be cleared and no message triggered.</p>
<p>The node can be configured to resend a message at a regular interval until it <p>The node can be configured to resend a message at a regular interval until it
is reset by a received message.</p> is reset by a received message.</p>
</script> </script>

View File

@ -104,6 +104,7 @@ module.exports = function(RED) {
if (node.duration === 0) { node.topics[topic].tout = 0; } if (node.duration === 0) { node.topics[topic].tout = 0; }
else if (node.loop === true) { else if (node.loop === true) {
/* istanbul ignore else */
if (node.topics[topic].tout) { clearInterval(node.topics[topic].tout); } if (node.topics[topic].tout) { clearInterval(node.topics[topic].tout); }
/* istanbul ignore else */ /* istanbul ignore else */
if (node.op1type !== "nul") { if (node.op1type !== "nul") {
@ -129,16 +130,19 @@ module.exports = function(RED) {
} }
else if ((node.extend === "true" || node.extend === true) && (node.duration > 0)) { else if ((node.extend === "true" || node.extend === true) && (node.duration > 0)) {
/* istanbul ignore else */ /* 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); } 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() { node.topics[topic].tout = setTimeout(function() {
if (node.op2type !== "nul") { if (node.op2type !== "nul") {
var msg2 = RED.util.cloneMessage(msg); var msg2 = RED.util.cloneMessage(msg);
if (node.op2type === "flow" || node.op2type === "global") { if (node.op2type === "flow" || node.op2type === "global") {
node.topics[topic].m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg); node.topics[topic].m2 = RED.util.evaluateNodeProperty(node.op2,node.op2type,node,msg);
} }
msg2.payload = node.topics[topic].m2; if (node.topics[topic] !== undefined) {
node.send(msg2); msg2.payload = node.topics[topic].m2;
node.send(msg2);
}
} }
delete node.topics[topic]; delete node.topics[topic];
node.status({}); node.status({});

View File

@ -282,7 +282,7 @@ describe('trigger node', function() {
n1.emit("input", {payload:1,topic:"A"}); n1.emit("input", {payload:1,topic:"A"});
n1.emit("input", {payload:2,topic:"B"}); n1.emit("input", {payload:2,topic:"B"});
n1.emit("input", {payload:3,topic:"C"}); 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 );
}); });
}); });