experimenting with 'reserved uids'
This commit is contained in:
@@ -35,8 +35,8 @@ module.exports = (user_list)->
|
||||
user.getConnector().receive(o)
|
||||
|
||||
receive: (o)->
|
||||
@unexecuted[o.creator] ?= []
|
||||
@unexecuted[o.creator].push o
|
||||
@unexecuted[o.uid.creator] ?= []
|
||||
@unexecuted[o.uid.creator].push o
|
||||
|
||||
flushOne: (user)->
|
||||
if @unexecuted[user]?.length > 0
|
||||
|
||||
@@ -14,6 +14,9 @@ class Engine
|
||||
throw new Error "You forgot to specify a parser for type #{json.type}. The message is #{JSON.stringify json}."
|
||||
|
||||
applyOps: (ops_json)->
|
||||
for o in ops_json
|
||||
@applyOp o
|
||||
###
|
||||
ops = []
|
||||
for o in ops_json
|
||||
ops.push @parseOperation o
|
||||
@@ -23,7 +26,7 @@ class Engine
|
||||
if not o.execute()
|
||||
@unprocessed_ops.push o
|
||||
@tryUnprocessed()
|
||||
|
||||
###
|
||||
applyOp: (op_json)->
|
||||
# $parse_and_execute will return false if $o_json was parsed and executed, otherwise the parsed operadion
|
||||
o = @parseOperation op_json
|
||||
@@ -43,7 +46,7 @@ class Engine
|
||||
if @unprocessed_ops.length is old_length
|
||||
break
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = Engine
|
||||
|
||||
@@ -16,14 +16,11 @@ class JsonYatta
|
||||
json_types = json_types_uninitialized @HB
|
||||
@engine = new Engine @HB, json_types.parser
|
||||
@connector = new Connector @engine, @HB, json_types.execution_listener, @
|
||||
root_elem = @connector.getRootElement()
|
||||
if not root_elem?
|
||||
first_word = new json_types.types.JsonType @HB.getNextOperationIdentifier()
|
||||
@HB.addOperation(first_word)
|
||||
first_word.execute()
|
||||
@root_element = first_word
|
||||
else
|
||||
@root_element = @HB.getOperation(root_elem)
|
||||
|
||||
first_word = new json_types.types.JsonType @HB.getReservedUniqueIdentifier()
|
||||
@HB.addOperation(first_word).execute()
|
||||
@root_element = first_word
|
||||
|
||||
|
||||
#
|
||||
# @result JsonType
|
||||
|
||||
@@ -21,6 +21,18 @@ class HistoryBuffer
|
||||
getUserId: ()->
|
||||
@user_id
|
||||
|
||||
#
|
||||
# There is only one reserved unique identifier (uid), so use it wisely.
|
||||
# I propose to use it in your Framework, to create something like a root element.
|
||||
# An operation with this identifier is not propagated to other clients.
|
||||
# This is why everybode must create the same operation with this uid.
|
||||
#
|
||||
getReservedUniqueIdentifier: ()->
|
||||
{
|
||||
creator : '_'
|
||||
op_number : '_'
|
||||
}
|
||||
|
||||
#
|
||||
# Get the operation counter that describes the current state of the document.
|
||||
#
|
||||
|
||||
@@ -294,7 +294,7 @@ module.exports = (HB)->
|
||||
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
|
||||
# @param {Object} content
|
||||
#
|
||||
constructor: (uid, @content="", prev, next, origin)->
|
||||
constructor: (uid, @content, prev, next, origin)->
|
||||
super uid, prev, next, origin
|
||||
|
||||
#
|
||||
|
||||
@@ -155,10 +155,11 @@ module.exports = (HB)->
|
||||
super name, obj
|
||||
else
|
||||
if typeof content is 'string'
|
||||
word = HB.addOperation(new types.Word HB.getNextOperationIdentifier(), content).execute()
|
||||
word = HB.addOperation(new types.Word undefined).execute()
|
||||
word.insertText 0, content
|
||||
super name, word
|
||||
else if content.constructor is Object
|
||||
json = HB.addOperation(new JsonType HB.getNextOperationIdentifier(), content, mutable).execute()
|
||||
json = HB.addOperation(new JsonType undefined, content, mutable).execute()
|
||||
super name, json
|
||||
else
|
||||
throw new Error "You must not set #{typeof content}-types in collaborative Json-objects!"
|
||||
|
||||
@@ -20,7 +20,7 @@ module.exports = (HB)->
|
||||
val: (name, content)->
|
||||
if content?
|
||||
if not @map[name]?
|
||||
HB.addOperation(new AddName HB.getNextOperationIdentifier(), @, name).execute()
|
||||
HB.addOperation(new AddName undefined, @, name).execute()
|
||||
@map[name].replace content
|
||||
@
|
||||
else if name?
|
||||
@@ -103,14 +103,14 @@ module.exports = (HB)->
|
||||
@saveOperation 'beginning', beginning
|
||||
@saveOperation 'end', end
|
||||
else
|
||||
@beginning = HB.addOperation new types.Delimiter HB.getNextOperationIdentifier(), undefined, undefined
|
||||
@end = HB.addOperation new types.Delimiter HB.getNextOperationIdentifier(), @beginning, undefined
|
||||
@beginning = HB.addOperation new types.Delimiter undefined, undefined, undefined
|
||||
@end = HB.addOperation new types.Delimiter undefined, @beginning, undefined
|
||||
@beginning.next_cl = @end
|
||||
@beginning.execute()
|
||||
@end.execute()
|
||||
|
||||
super uid, prev, next, origin
|
||||
|
||||
|
||||
# Get the element previous to the delemiter at the end
|
||||
getLastOperation: ()->
|
||||
@end.prev_cl
|
||||
@@ -165,7 +165,7 @@ module.exports = (HB)->
|
||||
|
||||
replace: (content)->
|
||||
o = @getLastOperation()
|
||||
op = new Replaceable content, @, HB.getNextOperationIdentifier(), o, o.next_cl
|
||||
op = new Replaceable content, @, undefined, o, o.next_cl
|
||||
HB.addOperation(op).execute()
|
||||
|
||||
val: ()->
|
||||
|
||||
@@ -78,19 +78,17 @@ module.exports = (HB)->
|
||||
|
||||
#
|
||||
# @param {Object} uid A unique identifier. If uid is undefined, a new uid will be created.
|
||||
# @param {String} initial_content
|
||||
#
|
||||
constructor: (uid, initial_content, beginning, end, prev, next, origin)->
|
||||
constructor: (uid, beginning, end, prev, next, origin)->
|
||||
super uid, beginning, end, prev, next, origin
|
||||
if initial_content?
|
||||
@insertText 0, initial_content
|
||||
|
||||
#
|
||||
# Inserts a string into the word
|
||||
#
|
||||
insertText: (position, content)->
|
||||
o = @getOperationByPosition position
|
||||
for c in content
|
||||
op = new TextInsert c, HB.getNextOperationIdentifier(), o.prev_cl, o
|
||||
op = new TextInsert c, undefined, o.prev_cl, o
|
||||
HB.addOperation(op).execute()
|
||||
|
||||
#
|
||||
@@ -166,7 +164,7 @@ module.exports = (HB)->
|
||||
'next': next
|
||||
'origin' : origin
|
||||
} = json
|
||||
new Word uid, undefined, beginning, end, prev, next, origin
|
||||
new Word uid, beginning, end, prev, next, origin
|
||||
|
||||
types['TextInsert'] = TextInsert
|
||||
types['TextDelete'] = TextDelete
|
||||
|
||||
Reference in New Issue
Block a user