Everything is working smoothly again. Execution speed increased by 10x. Cleaned up the code and unused stuff.
This commit is contained in:
@@ -77,8 +77,6 @@ class Engine
|
||||
if @HB.getOperation(op)?
|
||||
else if not op.execute()
|
||||
unprocessed.push op
|
||||
else
|
||||
@HB.addOperation op
|
||||
@unprocessed_ops = unprocessed
|
||||
if @unprocessed_ops.length is old_length
|
||||
break
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#
|
||||
class HistoryBuffer
|
||||
|
||||
|
||||
|
||||
#
|
||||
# Creates an empty HB.
|
||||
# @param {Object} user_id Creator of the HB.
|
||||
@@ -84,7 +82,6 @@ class HistoryBuffer
|
||||
else
|
||||
@operation_counter[user_id]
|
||||
|
||||
|
||||
#
|
||||
# Encode this operation in such a way that it can be parsed by remote peers.
|
||||
# TODO: Make this more efficient!
|
||||
@@ -98,7 +95,7 @@ class HistoryBuffer
|
||||
for u_name,user of @buffer
|
||||
# TODO next, if @state_vector[user] <= state_vector[user]
|
||||
for o_number,o of user
|
||||
if o.doSync and unknown(u_name, o_number)
|
||||
if o.uid.doSync and unknown(u_name, o_number)
|
||||
# its necessary to send it, and not known in state_vector
|
||||
o_json = o._encode()
|
||||
if o.next_cl? # applies for all ops but the most right delimiter!
|
||||
@@ -137,12 +134,11 @@ class HistoryBuffer
|
||||
#
|
||||
# Retrieve an operation from a unique id.
|
||||
#
|
||||
getOperation: (uid)->
|
||||
if uid instanceof Object
|
||||
@buffer[uid.creator]?[uid.op_number]
|
||||
else if not uid?
|
||||
else
|
||||
throw new Error "This type of uid is not defined!"
|
||||
getOperation: (uid)->
|
||||
if uid.uid?
|
||||
uid = uid.uid
|
||||
@buffer[uid.creator]?[uid.op_number]
|
||||
|
||||
#
|
||||
# Add an operation to the HB. Note that this will not link it against
|
||||
# other operations (it wont executed)
|
||||
|
||||
@@ -118,7 +118,7 @@ module.exports = (HB)->
|
||||
@uid
|
||||
|
||||
dontSync: ()->
|
||||
@doSync = false
|
||||
@uid.doSync = false
|
||||
|
||||
#
|
||||
# @private
|
||||
@@ -279,7 +279,7 @@ module.exports = (HB)->
|
||||
applyDelete: (o)->
|
||||
@deleted_by ?= []
|
||||
callLater = false
|
||||
if @parent? and not @isDeleted()
|
||||
if @parent? and not @isDeleted() and o? # o? : if not o?, then the delimiter deleted this Insertion. Furthermore, it would be wrong to call it. TODO: make this more expressive and save
|
||||
# call iff wasn't deleted earlyer
|
||||
callLater = true
|
||||
if o?
|
||||
@@ -384,10 +384,11 @@ module.exports = (HB)->
|
||||
@next_cl.prev_cl = @
|
||||
|
||||
parent = @prev_cl?.getParent()
|
||||
super # notify the execution_listeners
|
||||
if parent? and fire_event
|
||||
@setParent parent
|
||||
@parent.callEvent "insert", @
|
||||
super # notify the execution_listeners
|
||||
@
|
||||
|
||||
#
|
||||
# Compute the position of this operation.
|
||||
@@ -493,13 +494,13 @@ module.exports = (HB)->
|
||||
if @prev_cl.next_cl?
|
||||
throw new Error "Probably duplicated operations"
|
||||
@prev_cl.next_cl = @
|
||||
delete @prev_cl.unchecked.next_cl
|
||||
super
|
||||
else
|
||||
false
|
||||
else if @prev_cl? and not @prev_cl.next_cl?
|
||||
delete @prev_cl.unchecked.next_cl
|
||||
@prev_cl.next_cl = @
|
||||
super
|
||||
else if @prev_cl? or @next_cl? or true # TODO: are you sure? This can happen right?
|
||||
super
|
||||
#else
|
||||
|
||||
@@ -122,11 +122,11 @@ module.exports = (HB)->
|
||||
# @return {Json}
|
||||
#
|
||||
toJson: ()->
|
||||
if not @bound_json? or not Object.observe?
|
||||
if not @bound_json? or not Object.observe? or true # TODO: currently, you are not watching mutable strings for changes, and, therefore, the @bound_json is not updated. TODO TODO wuawuawua easy
|
||||
val = @val()
|
||||
json = {}
|
||||
for name, o of val
|
||||
if o is null
|
||||
if not o?
|
||||
json[name] = o
|
||||
else if o.constructor is {}.constructor
|
||||
json[name] = @val(name).toJson()
|
||||
|
||||
@@ -91,7 +91,7 @@ module.exports = (HB)->
|
||||
# always have the same result (ReplaceManager, and its beginning and end are the same)
|
||||
#
|
||||
execute: ()->
|
||||
if not @validateSavedOperations()
|
||||
if not @validateSavedOperations()
|
||||
return false
|
||||
else
|
||||
# helper for cloning an object
|
||||
@@ -105,9 +105,9 @@ module.exports = (HB)->
|
||||
uid_r.op_number = "_#{uid_r.op_number}_RM_#{@name}"
|
||||
if not HB.getOperation(uid_r)?
|
||||
uid_beg = clone(uid_r)
|
||||
uid_beg.op_number = "_#{uid_beg.op_number}_RM_#{@name}_beginning"
|
||||
uid_beg.op_number = "#{uid_r.op_number}_beginning"
|
||||
uid_end = clone(uid_r)
|
||||
uid_end.op_number = "_#{uid_end.op_number}_RM_#{@name}_end"
|
||||
uid_end.op_number = "#{uid_r.op_number}_end"
|
||||
beg = (new types.Delimiter uid_beg, undefined, uid_end).execute()
|
||||
end = (new types.Delimiter uid_end, beg, undefined).execute()
|
||||
@map_manager.map[@name] = new ReplaceManager undefined, uid_r, beg, end
|
||||
|
||||
@@ -143,7 +143,8 @@ module.exports = (HB)->
|
||||
(new TextInsert content, undefined, left, right).execute()
|
||||
else
|
||||
for c in content
|
||||
left = (new TextInsert c, undefined, left, right).execute()
|
||||
tmp = (new TextInsert c, undefined, left, right).execute()
|
||||
left = tmp
|
||||
@
|
||||
#
|
||||
# Inserts a string into the word.
|
||||
|
||||
@@ -4,17 +4,16 @@ HistoryBuffer = require "./HistoryBuffer"
|
||||
Engine = require "./Engine"
|
||||
adaptConnector = require "./ConnectorAdapter"
|
||||
|
||||
|
||||
#
|
||||
# Framework for Json data-structures.
|
||||
# Known values that are supported:
|
||||
# * String
|
||||
# * Integer
|
||||
# * Array
|
||||
# * Array
|
||||
#
|
||||
class Yatta
|
||||
|
||||
#
|
||||
#
|
||||
# @param {String} user_id Unique id of the peer.
|
||||
# @param {Connector} Connector the connector class.
|
||||
#
|
||||
@@ -35,7 +34,7 @@ class Yatta
|
||||
|
||||
@root_element = (new @types.ReplaceManager undefined, @HB.getReservedUniqueIdentifier(), beg, end).execute()
|
||||
@root_element.replace first_word, @HB.getReservedUniqueIdentifier()
|
||||
|
||||
|
||||
#
|
||||
# @return JsonType
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user