I'm surprised this hasn't been discovered before as it's a major bug.
var assert = require('assert');
var Emitter = require('tiny-emitter');
var emitter = new Emitter();
var pleaseNeverCallMe = assert.bind(assert, false, 'You called me, didn\'t you?');
var pleaseNeverCallMeEvenOnce = assert.bind(assert, false, 'You called me, didn\'t you?');
emitter.on('some-event', pleaseNeverCallMe);
emitter.once('some-event', pleaseNeverCallMeEvenOnce);
emitter.off('some-event', pleaseNeverCallMe);
emitter.off('some-event', pleaseNeverCallMeEvenOnce);
emitter.emit('some-event');
The cause is simple: you use on internally with a wrapper function, not the original one.
I just randomly chose another module and checked how they do it. E.g. little-emitter. They add a property to the wrapper function which references the original one.
I'm surprised this hasn't been discovered before as it's a major bug.
The cause is simple: you use
on
internally with a wrapper function, not the original one.I just randomly chose another module and checked how they do it. E.g. little-emitter. They add a property to the wrapper function which references the original one.
https://github.com/Alex1990/little-emitter/blob/master/emitter.js#L58 https://github.com/Alex1990/little-emitter/blob/master/emitter.js#L78