Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove ability to pass array of event names to EventEmitter.prototype…
….once This copies across the change from commit cd4f7b3 in ably-js: > This functionality is implemented by wrapping the listener argument in > another listener. This means that the event emitter does not hold a > reference to the listener argument (other than that held indirectly > through the wrapper) and so it is not possible to remove this listener > using `off(..., listener)`. > > The client library specification does not specify a version of `once` > which accepts an array of event names, and we do not advertise it as > part of the public API. So, I think the simplest thing is to remove this > functionality. The removed code in the current commit also had a bug — the second argument in the removed code `self.off(eventName, this)` was incorrectly populated and this made the removed code equivalent to `self.off(eventName)`; that is, it removed _all_ listeners for the given event name. I believe that the removal of this code accounts for the increased expected number of calls to context.spy in one of the tests here. I’m not sure what reasoning led to the previous expected count of 3 (perhaps the expectation was written just based on the number of calls observed when running the code), but here’s my reasoning for the expectation of 4 calls: Before `context.eventEmitter['off']('myEvent', context.spy)`, the following calls are relevant to context.spy: - eventEmitter['on'](context.spy); - eventEmitter['on']('myEvent', context.spy); - eventEmitter['on'](['myEvent', 'myOtherEvent', 'myThirdEvent'], context.spy); - eventEmitter['once'](context.spy); - eventEmitter['once']('myEvent', context.spy); After `context.eventEmitter['off']('myEvent', context.spy)`, the following calls are relevant to context.spy: - eventEmitter['on'](context.spy); - eventEmitter['on'](['myEvent' /* no longer applies */, 'myOtherEvent', 'myThirdEvent'], context.spy); - eventEmitter['once'](context.spy); After `context.eventEmitter['emit']('myEvent', '')`, the following calls are relevant to context.spy: - eventEmitter['on'](context.spy); - eventEmitter['on'](['myEvent' /* no longer applies *\/, 'myOtherEvent', 'myThirdEvent'], context.spy); And hence calling `context.eventEmitter['emit']('myOtherEvent', '')` calls context.spy a further two times.
- Loading branch information