UNPKG

node-red-contrib-repeat

Version:

Limit the number of times a message is allowed to pass through the node before it is discarded

47 lines (44 loc) 2.4 kB
<script type="text/javascript"> RED.nodes.registerType('repeat',{ category: 'function', color: '#E2D96E', defaults: { name: {value: ""}, repetitions: {}, elseOutput: {value: false}, outputs: {value: 1} // Ofuscated way to persist the number of outputs of the node }, inputs: 1, outputs: 1, icon: "repeat.png", label: function() { return this.name || "Repeat " + (this.repetitions || "N") + " times"; }, oneditsave: function () { var elseOutputActivated = document.getElementById('node-input-elseOutput').checked; this.outputs = elseOutputActivated ? 2 : 1; } }); </script> <script type="text/x-red" data-template-name="repeat"> <div class="form-row"> <label for="node-input-name"><i class="icon-tag"></i> Name</label> <input type="text" id="node-input-name" placeholder="Name"> </div> <div class="form-row"> <label for="node-input-repetitions"><i class="fa fa-undo"></i> Repetitions</label> <input type="number" id="node-input-repetitions", style="width:80px"> </div> <div class="form-row"> <label for="node-input-elseOutput"><i class="icon-random"></i> Else Output</label> <input type="checkbox" id="node-input-elseOutput", style="width:auto;vertical-align:top"> </div> </script> <script type="text/x-red" data-help-name="repeat"> <p>Allow a message to pass through this node for an specific number of times, after which it will be discarded, unveiling the ability to limit the loops over a flow to N times.</p> <p>If <code>Else Output</code> is activated, a second output is enabled that will receive the message once when the repetitions have been exhausted</p> <p>The number of times the message can loop can be configured in the node or specified in the <code>msg.repetitions</code> property which, as usual, will take precedence over the node configuration</p> <p>Note: This node will create a new property <b>msg._loopController</b> that will hold the loop state for that message, including information about the <b>loops</b> executed and the <b>remaining</b> loops.</p> <p><b>Currently there is no support for more than one <code>repeat</code> node operating upon a message simultaneously</b></p> </script>