fixes issue #1 and #2

This commit is contained in:
Kevin Jahns
2014-08-21 04:19:55 +02:00
parent 465a2f18e6
commit ad5898a77a
29 changed files with 323 additions and 77 deletions

View File

@@ -52,10 +52,16 @@ module.exports = (HB)->
# Fire an event.
# TODO: Do something with timeouts. You don't want this to fire for every operation (e.g. insert).
#
callEvent: (event, args...)->
callEvent: ()->
@forwardEvent @, arguments...
#
# Fire an event and specify in which context the listener is called (set 'this').
#
forwardEvent: (op, event, args...)->
if @event_listeners?[event]?
for f in @event_listeners[event]
f.call @, event, args...
f.call op, event, args...
#
# Set the parent of this operation.

View File

@@ -127,6 +127,21 @@ module.exports = (HB)->
json[name] = o
json
#
# @see Word.setReplaceManager
# Sets the parent of this JsonType object.
#
setReplaceManager: (rm)->
@parent = rm.parent
@on ['change','addProperty'], ()->
rm.parent.forwardEvent this, arguments...
#
# Get the parent of this JsonType.
# @return {JsonType}
#
getParent: ()->
@parent
#
# Whether the default is 'mutable' (true) or 'immutable' (false)
#

View File

@@ -80,7 +80,6 @@ module.exports = (HB)->
@map_manager.map[@name] = HB.addOperation(new ReplaceManager undefined, uid_r, beg, end)
@map_manager.map[@name].setParent @map_manager, @name
@map_manager.map[@name].execute()
@map_manager.callEvent 'addProperty', @name
super
#
@@ -208,6 +207,12 @@ module.exports = (HB)->
@parent.callEvent 'change', property_name
@on 'change', (event)=>
@parent.callEvent 'change', property_name
# Call this, when the first element is inserted. Then delete the listener.
addPropertyListener = (event, op)=>
if op.next_cl instanceof types.Delimiter and op.prev_cl instanceof types.Delimiter
@parent.callEvent 'addProperty', property_name
@deleteListener 'addProperty', addPropertyListener
@on 'insert', addPropertyListener
super parent
#
# Get the value of this Word