mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-11-13 08:44:12 +03:00
Allow off
to be called before on
without error
Previously calling `something.off 'event-name', handler` would throw an error unless `on` was called first.
This commit is contained in:
parent
7e9c39fd55
commit
9cc4c2e5de
@ -109,6 +109,9 @@ describe "EventEmitter mixin", ->
|
||||
expect(fooHandler1).not.toHaveBeenCalled()
|
||||
expect(fooHandler2).toHaveBeenCalled()
|
||||
|
||||
it "does not throw an exception if there was not matching `on` call", ->
|
||||
expect(-> object.off 'marco', -> "nothing").not.toThrow()
|
||||
|
||||
describe "when there are namespaced event handlers", ->
|
||||
[barHandler2, bazHandler1, bazHandler2, bazHandler3] = []
|
||||
|
||||
|
@ -78,8 +78,8 @@ module.exports =
|
||||
@off eventName, handler
|
||||
else
|
||||
subscriptionCountBefore = @subscriptionCount()
|
||||
if handler
|
||||
_.remove(@eventHandlersByEventName[eventName], handler)
|
||||
if eventHandlers = @eventHandlersByEventName[eventName]
|
||||
_.remove(eventHandlers, handler)
|
||||
else
|
||||
delete @eventHandlersByEventName?[eventName]
|
||||
@afterUnsubscribe?() if @subscriptionCount() < subscriptionCountBefore
|
||||
|
Loading…
Reference in New Issue
Block a user