mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Fix this
context when calling multiple event listeners (fixes #2692).
This commit is contained in:
parent
0c5eae2349
commit
d84c2b780b
@ -214,7 +214,8 @@ Node.prototype._emitInput = function(arg) {
|
||||
c++;
|
||||
}
|
||||
try {
|
||||
node._inputCallbacks[i](
|
||||
cb.call(
|
||||
node,
|
||||
arg,
|
||||
function() { node.send.apply(node,arguments) },
|
||||
function(err) {
|
||||
|
@ -216,6 +216,7 @@ describe('Node', function() {
|
||||
n2.on('input',function(msg) {
|
||||
// msg equals message, and is not a new copy
|
||||
messageReceived = true;
|
||||
should.strictEqual(this,n2);
|
||||
should.deepEqual(msg,message);
|
||||
should.strictEqual(msg,message);
|
||||
done();
|
||||
@ -224,6 +225,34 @@ describe('Node', function() {
|
||||
messageReceived.should.be.false();
|
||||
});
|
||||
|
||||
it('emits a single message - multiple input event listeners', function(done) {
|
||||
var flow = {
|
||||
getNode: (id) => { return {'n1':n1,'n2':n2}[id]},
|
||||
};
|
||||
var n1 = new RedNode({_flow:flow,id:'n1',type:'abc',wires:[['n2']]});
|
||||
var n2 = new RedNode({_flow:flow,id:'n2',type:'abc'});
|
||||
var message = {payload:"hello world"};
|
||||
var messageReceived = 0;
|
||||
n2.on('input',function(msg) {
|
||||
// msg equals message, and is not a new copy
|
||||
messageReceived++;
|
||||
messageReceived.should.be.exactly(1);
|
||||
should.strictEqual(this,n2);
|
||||
should.deepEqual(msg,message);
|
||||
should.strictEqual(msg,message);
|
||||
});
|
||||
n2.on('input',function() {
|
||||
messageReceived++;
|
||||
messageReceived.should.be.exactly(2);
|
||||
should.strictEqual(this,n2);
|
||||
should.deepEqual(msg,message);
|
||||
should.strictEqual(msg,message);
|
||||
done();
|
||||
});
|
||||
n1.send(message);
|
||||
messageReceived.should.be.exactly(0);
|
||||
});
|
||||
|
||||
it('emits a single message - synchronous mode', function(done) {
|
||||
var flow = {
|
||||
getNode: (id) => { return {'n1':n1,'n2':n2}[id]},
|
||||
|
Loading…
Reference in New Issue
Block a user