mirror of
https://github.com/node-red/node-red
synced 2024-11-23 00:52:33 +00:00
Client Events: fix off-in-on pattern emulating once
This fixes an issue when RED.events.off(..) is called in a RED.events.on(..) callback: ``` let cb = () => { RED.events.off("event-name", cb) .... } RED.events.on("event-name", cb) ``` This pattern emulates a once(..), i.e., execute a callback once-only for an event. Discussed in [Forum](https://discourse.nodered.org/t/event-offing-an-on-event-to-perform-only-once/83726)
This commit is contained in:
parent
0e8d312794
commit
e1f2e0656b
@ -39,15 +39,16 @@
|
||||
console.warn(evt,args);
|
||||
}
|
||||
if (handlers[evt]) {
|
||||
for (var i=0;i<handlers[evt].length;i++) {
|
||||
let cpyHandlers = [...handlers[evt]];
|
||||
|
||||
for (var i=0;i<cpyHandlers.length;i++) {
|
||||
try {
|
||||
handlers[evt][i].apply(null, args);
|
||||
cpyHandlers[i].apply(null, args);
|
||||
} catch(err) {
|
||||
console.warn("RED.events.emit error: ["+evt+"] "+(err.toString()));
|
||||
console.warn(err);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user