mirror of
https://github.com/atom/atom.git
synced 2026-02-18 02:21:43 -05:00
Start on CommandRegistry
This commit is contained in:
21
src/command-registry.coffee
Normal file
21
src/command-registry.coffee
Normal file
@@ -0,0 +1,21 @@
|
||||
module.exports =
|
||||
class CommandRegistry
|
||||
constructor: (@rootNode) ->
|
||||
@listenersByCommandName = {}
|
||||
|
||||
add: (commandName, selector, callback) ->
|
||||
unless @listenersByCommandName[commandName]?
|
||||
@rootNode.addEventListener(commandName, @dispatchCommand, true)
|
||||
@listenersByCommandName[commandName] = []
|
||||
|
||||
@listenersByCommandName[commandName].push({selector, callback})
|
||||
|
||||
dispatchCommand: (event) =>
|
||||
syntheticEvent = Object.create event,
|
||||
eventPhase: value: Event.BUBBLING_PHASE
|
||||
currentTarget: get: -> currentTarget
|
||||
|
||||
currentTarget = event.target
|
||||
for listener in @listenersByCommandName[event.type]
|
||||
if event.target.webkitMatchesSelector(listener.selector)
|
||||
listener.callback.call(currentTarget, syntheticEvent)
|
||||
Reference in New Issue
Block a user