Allow CommandRegistry::rootNode to be assigned after construction

This commit is contained in:
Nathan Sobo
2014-09-05 15:48:10 -06:00
parent 43d3082d4e
commit 7580d64d2e

View File

@@ -9,6 +9,12 @@ class CommandRegistry
constructor: (@rootNode) ->
@listenersByCommandName = {}
setRootNode: (rootNode) ->
throw new Error("Already assigned root node.") if @rootNode?
@rootNode = rootNode
for commandName of @listenersByCommandName
@rootNode?.addEventListener(commandName, @dispatchCommand, true)
add: (selector, commandName, callback) ->
if typeof commandName is 'object'
commands = commandName
@@ -18,7 +24,7 @@ class CommandRegistry
return disposable
unless @listenersByCommandName[commandName]?
@rootNode.addEventListener(commandName, @dispatchCommand, true)
@rootNode?.addEventListener(commandName, @dispatchCommand, true)
@listenersByCommandName[commandName] = []
listener = new CommandListener(selector, callback)