Merge pull request #8848 from atom/ns-mb-assign-non-standard-command-event-properties

Hotfix: Preserve all event properties when dispatching commands
This commit is contained in:
Nathan Sobo
2015-09-18 11:20:39 -06:00
2 changed files with 12 additions and 0 deletions

View File

@@ -115,6 +115,15 @@ describe "CommandRegistry", ->
grandchild.dispatchEvent(dispatchedEvent)
expect(dispatchedEvent.abortKeyBinding).toHaveBeenCalled()
it "copies non-standard properties from the original event to the synthetic event", ->
syntheticEvent = null
registry.add '.child', 'command', (event) -> syntheticEvent = event
dispatchedEvent = new CustomEvent('command', bubbles: true)
dispatchedEvent.nonStandardProperty = 'testing'
grandchild.dispatchEvent(dispatchedEvent)
expect(syntheticEvent.nonStandardProperty).toBe 'testing'
it "allows listeners to be removed via a disposable returned by ::add", ->
calls = []

View File

@@ -227,6 +227,9 @@ class CommandRegistry
Object.defineProperty dispatchedEvent, 'abortKeyBinding', value: ->
event.abortKeyBinding?()
for key in Object.keys(event)
dispatchedEvent[key] = event[key]
@emitter.emit 'will-dispatch', dispatchedEvent
loop