fixed error with native event listeners

This commit is contained in:
DadaMonad
2014-12-01 11:01:14 +00:00
parent e1900e8561
commit d4bb2dc173
39 changed files with 326 additions and 779 deletions

View File

@@ -68,6 +68,14 @@ module.exports = (HB)->
if @event_listeners?[e]?
@event_listeners[e] = @event_listeners[e].filter (g)->
f isnt g
#
# Deletes all subscribed event listeners.
# This should be called, e.g. after this has been replaced.
# (Then only one replace event should fire. )
# This is also called in the cleanup method.
deleteAllListeners: ()->
@event_listeners = []
#
# Fire an event.
@@ -98,6 +106,7 @@ module.exports = (HB)->
cleanup: ()->
#console.log "cleanup: #{@type}"
HB.removeOperation @
@deleteAllListeners()
#
# Set the parent of this operation.

View File

@@ -128,25 +128,28 @@ module.exports = (HB)->
cleanup: ()->
super()
#
# Transform this to a Json and loose all the sharing-abilities (the new object will be a deep clone)!
# @return {Json}
#
toJson: ()->
val = @val()
json = {}
for name, o of val
if o is null
json[name] = o
else if o.constructor is {}.constructor
json[name] = @val(name).toJson()
else if o instanceof types.Operation
while o instanceof types.Operation
o = o.val()
json[name] = o
else
json[name] = o
json
if not @bound_json?
val = @val()
json = {}
for name, o of val
if o is null
json[name] = o
else if o.constructor is {}.constructor
json[name] = @val(name).toJson()
else if o instanceof types.Operation
while o instanceof types.Operation
o = o.val()
json[name] = o
else
json[name] = o
@bound_json = json
@bound_json
#
# @see WordType.setReplaceManager

View File

@@ -257,7 +257,7 @@ module.exports = (HB)->
repl_manager.parent.callEvent 'change', property_name, op
# Call this, when the first element is inserted. Then delete the listener.
addPropertyListener = (event, op)->
repl_manager.deleteListener 'addProperty', addPropertyListener
repl_manager.deleteListener 'insert', addPropertyListener
repl_manager.parent.callEvent 'addProperty', property_name, op
@on 'insert', addPropertyListener
super parent
@@ -338,6 +338,8 @@ module.exports = (HB)->
applyDelete: ()->
if @content?
if @next_cl.type isnt "Delimiter"
@content.deleteAllListeners()
@content.applyDelete()
@content.dontSync()
@content = null