Initial Commit -> Text collaboration works
This commit is contained in:
51
lib/Connectors/TestConnector.coffee
Normal file
51
lib/Connectors/TestConnector.coffee
Normal file
@@ -0,0 +1,51 @@
|
||||
|
||||
_ = require "underscore"
|
||||
|
||||
module.exports = (user_list)->
|
||||
class TestConnector
|
||||
constructor: (@engine, @HB, @execution_listener)->
|
||||
send_ = (o)=>
|
||||
@send o
|
||||
@execution_listener.push send_
|
||||
|
||||
if not (user_list?.length is 0)
|
||||
@engine.applyOps user_list[0].getHistoryBuffer().toJson()
|
||||
|
||||
@unexecuted = {}
|
||||
@applied_operations = []
|
||||
|
||||
appliedOperationsListener = (o)=>
|
||||
@applied_operations.push o
|
||||
@execution_listener.push appliedOperationsListener
|
||||
|
||||
getOpsInExecutionOrder: ()->
|
||||
@applied_operations
|
||||
|
||||
getRootElement: ()->
|
||||
if user_list.length > 0
|
||||
user_list[0].getRootElement()
|
||||
|
||||
send: (o)->
|
||||
if o.creator is @HB.getUserId()
|
||||
for user in user_list
|
||||
if not user.getUserId() is @HB.getUserId()
|
||||
user.getConnector().receive(o)
|
||||
|
||||
receive: (o)->
|
||||
@unexecuted[o.creator] ?= []
|
||||
@unexecuted[o.creator].push o
|
||||
|
||||
flushOne: (user)->
|
||||
if @unexecuted[user]?.length > 0
|
||||
@engine.applyOp @unexecuted[user].shift()
|
||||
|
||||
flushOneRandom: ()->
|
||||
@flushOne (_.random 0, (user_list.length-1))
|
||||
|
||||
flushAll: ()->
|
||||
for ops of @unexecuted
|
||||
@engine.applyOps ops
|
||||
@unexecuted = {}
|
||||
|
||||
sync: ()->
|
||||
throw new Error "Can't use this a.t.m."
|
||||
Reference in New Issue
Block a user