Fix CommandRegistry::get/restoreSnapshot

I didn’t realize that deepClone was not handling functions correctly.
I’ve implemented clone manually to the exact depth needed instead.
This commit is contained in:
Nathan Sobo 2014-09-24 15:26:38 -06:00
parent d506ccbaad
commit 6d55bab4c8

View File

@ -152,12 +152,17 @@ class CommandRegistry
@handleCommandEvent(eventWithTarget)
getSnapshot: ->
_.deepClone(@listenersByCommandName)
snapshot = {}
for commandName, listeners of @listenersByCommandName
snapshot[commandName] = listeners.slice()
snapshot
restoreSnapshot: (snapshot) ->
rootNode = @getRootNode()
@setRootNode(null) # clear listeners for current commands
@listenersByCommandName = _.deepClone(snapshot)
@listenersByCommandName = {}
for commandName, listeners of snapshot
@listenersByCommandName[commandName] = listeners.slice()
@setRootNode(rootNode) # restore listeners for commands in snapshot
handleCommandEvent: (originalEvent) =>