mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2024-09-20 15:37:46 +03:00
Handle .stopPropagation() being called on command events
This commit is contained in:
parent
5eb22520f1
commit
fbaf956e1f
@ -57,3 +57,13 @@ describe "CommandRegistry", ->
|
|||||||
|
|
||||||
grandchild.dispatchEvent(new CustomEvent('command', bubbles: true))
|
grandchild.dispatchEvent(new CustomEvent('command', bubbles: true))
|
||||||
expect(calls).toEqual ['.foo.bar', '.bar', '.foo']
|
expect(calls).toEqual ['.foo.bar', '.bar', '.foo']
|
||||||
|
|
||||||
|
it "stops bubbling through ancestors when .stopPropagation() is called on the event", ->
|
||||||
|
calls = []
|
||||||
|
|
||||||
|
registry.add 'command', '.parent', -> calls.push('parent')
|
||||||
|
registry.add 'command', '.child', -> calls.push('child-2')
|
||||||
|
registry.add 'command', '.child', (event) -> calls.push('child-1'); event.stopPropagation()
|
||||||
|
|
||||||
|
grandchild.dispatchEvent(new CustomEvent('command', bubbles: true))
|
||||||
|
expect(calls).toEqual ['child-1', 'child-2']
|
||||||
|
@ -16,11 +16,14 @@ class CommandRegistry
|
|||||||
@listenersByCommandName[commandName].push(new CommandListener(selector, callback))
|
@listenersByCommandName[commandName].push(new CommandListener(selector, callback))
|
||||||
|
|
||||||
dispatchCommand: (event) =>
|
dispatchCommand: (event) =>
|
||||||
|
propagationStopped = false
|
||||||
|
currentTarget = event.target
|
||||||
|
|
||||||
syntheticEvent = Object.create event,
|
syntheticEvent = Object.create event,
|
||||||
eventPhase: value: Event.BUBBLING_PHASE
|
eventPhase: value: Event.BUBBLING_PHASE
|
||||||
currentTarget: get: -> currentTarget
|
currentTarget: get: -> currentTarget
|
||||||
|
stopPropagation: value: -> propagationStopped = true
|
||||||
|
|
||||||
currentTarget = event.target
|
|
||||||
loop
|
loop
|
||||||
matchingListeners =
|
matchingListeners =
|
||||||
@listenersByCommandName[event.type]
|
@listenersByCommandName[event.type]
|
||||||
@ -30,6 +33,7 @@ class CommandRegistry
|
|||||||
for listener in matchingListeners
|
for listener in matchingListeners
|
||||||
listener.callback.call(currentTarget, syntheticEvent)
|
listener.callback.call(currentTarget, syntheticEvent)
|
||||||
|
|
||||||
|
break if propagationStopped
|
||||||
break if currentTarget is @rootNode
|
break if currentTarget is @rootNode
|
||||||
currentTarget = currentTarget.parentNode
|
currentTarget = currentTarget.parentNode
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user