mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Only declare node variables inside node declaration.
Fix for Issue #119 (also reformatted with spaces hence what looks like massive changes...)
This commit is contained in:
parent
95b8600da7
commit
15669b7f1f
@ -15,12 +15,8 @@
|
|||||||
**/
|
**/
|
||||||
|
|
||||||
//Simple node to introduce a pause into a flow
|
//Simple node to introduce a pause into a flow
|
||||||
|
|
||||||
//Require main module
|
|
||||||
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
var RED = require(process.env.NODE_RED_HOME+"/red/red");
|
||||||
|
|
||||||
var node;
|
|
||||||
|
|
||||||
function random() {
|
function random() {
|
||||||
var wait = node.randomFirst + (node.diff * Math.random());
|
var wait = node.randomFirst + (node.diff * Math.random());
|
||||||
if (node.buffer.length > 0) {
|
if (node.buffer.length > 0) {
|
||||||
@ -31,7 +27,6 @@ function random() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//main node definition
|
|
||||||
function DelayNode(n) {
|
function DelayNode(n) {
|
||||||
RED.nodes.createNode(this,n);
|
RED.nodes.createNode(this,n);
|
||||||
|
|
||||||
@ -62,7 +57,6 @@ function DelayNode(n) {
|
|||||||
this.rate = (24 * 60 * 60 * 1000)/n.rate;
|
this.rate = (24 * 60 * 60 * 1000)/n.rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (n.randomUnits === "milliseconds") {
|
if (n.randomUnits === "milliseconds") {
|
||||||
this.randomFirst = n.randomFirst;
|
this.randomFirst = n.randomFirst;
|
||||||
this.randomLast = n.randomLast;
|
this.randomLast = n.randomLast;
|
||||||
@ -81,17 +75,16 @@ function DelayNode(n) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.diff = this.randomLast - this.randomFirst;
|
this.diff = this.randomLast - this.randomFirst;
|
||||||
|
|
||||||
this.name = n.name;
|
this.name = n.name;
|
||||||
this.idList = [];
|
this.idList = [];
|
||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
this.intervalID = -1;
|
this.intervalID = -1;
|
||||||
this.randomID = -1;
|
this.randomID = -1;
|
||||||
node= this;
|
var node = this;
|
||||||
|
|
||||||
if (this.pauseType === "delay") {
|
if (this.pauseType === "delay") {
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
var node= this;
|
node = this;
|
||||||
var id;
|
var id;
|
||||||
id = setTimeout(function(){
|
id = setTimeout(function(){
|
||||||
node.idList.splice(node.idList.indexOf(id),1);
|
node.idList.splice(node.idList.indexOf(id),1);
|
||||||
@ -106,8 +99,8 @@ function DelayNode(n) {
|
|||||||
}
|
}
|
||||||
this.idList = [];
|
this.idList = [];
|
||||||
});
|
});
|
||||||
} else if (this.pauseType === "rate") {
|
|
||||||
|
|
||||||
|
} else if (this.pauseType === "rate") {
|
||||||
this.on("input", function(msg) {
|
this.on("input", function(msg) {
|
||||||
if ( node.intervalID !== -1) {
|
if ( node.intervalID !== -1) {
|
||||||
node.buffer.push(msg);
|
node.buffer.push(msg);
|
||||||
@ -133,8 +126,8 @@ function DelayNode(n) {
|
|||||||
clearInterval(this.intervalID);
|
clearInterval(this.intervalID);
|
||||||
this.buffer = [];
|
this.buffer = [];
|
||||||
});
|
});
|
||||||
} else if (this.pauseType === "random") {
|
|
||||||
|
|
||||||
|
} else if (this.pauseType === "random") {
|
||||||
this.on("input",function(msg){
|
this.on("input",function(msg){
|
||||||
node.buffer.push(msg);
|
node.buffer.push(msg);
|
||||||
if (node.randomID === -1) {
|
if (node.randomID === -1) {
|
||||||
@ -145,13 +138,9 @@ function DelayNode(n) {
|
|||||||
|
|
||||||
this.on("close", function (){
|
this.on("close", function (){
|
||||||
if (this.randomID !== -1) {
|
if (this.randomID !== -1) {
|
||||||
clearTimeout(node.randomID);
|
clearTimeout(this.randomID);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//register node
|
|
||||||
RED.nodes.registerType("delay",DelayNode);
|
RED.nodes.registerType("delay",DelayNode);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user