1
0
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:
Dave C-J 2013-12-21 17:31:05 +00:00
parent 95b8600da7
commit 15669b7f1f

View File

@ -15,12 +15,8 @@
**/
//Simple node to introduce a pause into a flow
//Require main module
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var node;
function random() {
var wait = node.randomFirst + (node.diff * Math.random());
if (node.buffer.length > 0) {
@ -31,7 +27,6 @@ function random() {
}
}
//main node definition
function DelayNode(n) {
RED.nodes.createNode(this,n);
@ -62,7 +57,6 @@ function DelayNode(n) {
this.rate = (24 * 60 * 60 * 1000)/n.rate;
}
if (n.randomUnits === "milliseconds") {
this.randomFirst = n.randomFirst;
this.randomLast = n.randomLast;
@ -81,17 +75,16 @@ function DelayNode(n) {
}
this.diff = this.randomLast - this.randomFirst;
this.name = n.name;
this.idList = [];
this.buffer = [];
this.intervalID = -1;
this.randomID = -1;
node= this;
var node = this;
if (this.pauseType === "delay") {
this.on("input", function(msg) {
var node= this;
node = this;
var id;
id = setTimeout(function(){
node.idList.splice(node.idList.indexOf(id),1);
@ -106,8 +99,8 @@ function DelayNode(n) {
}
this.idList = [];
});
} else if (this.pauseType === "rate") {
} else if (this.pauseType === "rate") {
this.on("input", function(msg) {
if ( node.intervalID !== -1) {
node.buffer.push(msg);
@ -133,8 +126,8 @@ function DelayNode(n) {
clearInterval(this.intervalID);
this.buffer = [];
});
} else if (this.pauseType === "random") {
} else if (this.pauseType === "random") {
this.on("input",function(msg){
node.buffer.push(msg);
if (node.randomID === -1) {
@ -145,13 +138,9 @@ function DelayNode(n) {
this.on("close", function (){
if (this.randomID !== -1) {
clearTimeout(node.randomID);
clearTimeout(this.randomID);
}
});
}
}
//register node
RED.nodes.registerType("delay",DelayNode);