Allow multiple commands to be registered by passing an object

This commit is contained in:
Nathan Sobo
2014-09-05 09:54:02 -06:00
parent aee33fc126
commit 43d3082d4e
2 changed files with 26 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
{Disposable} = require 'event-kit'
{Disposable, CompositeDisposable} = require 'event-kit'
{specificity} = require 'clear-cut'
SequenceCount = 0
@@ -10,6 +10,13 @@ class CommandRegistry
@listenersByCommandName = {}
add: (selector, commandName, callback) ->
if typeof commandName is 'object'
commands = commandName
disposable = new CompositeDisposable
for commandName, callback of commands
disposable.add @add(selector, commandName, callback)
return disposable
unless @listenersByCommandName[commandName]?
@rootNode.addEventListener(commandName, @dispatchCommand, true)
@listenersByCommandName[commandName] = []