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CAAW,CAAA,CAAC,CAAC,SAAF,CAAnB,GAAkC,CAJlC,CAAA;aAKA,EANY;IAAA,CApId,CAAA;;AAAA,4BA4IA,eAAA,GAAiB,SAAC,CAAD,GAAA;AACf,UAAA,IAAA;uDAAA,MAAA,CAAA,IAA2B,CAAA,CAAC,CAAC,SAAF,WADZ;IAAA,CA5IjB,CAAA;;AAAA,4BAkJA,YAAA,GAAc,SAAC,CAAD,GAAA;AACZ,UAAA,QAAA;AAAA,MAAA,IAAO,yCAAP;AACE,QAAA,IAAC,CAAA,iBAAkB,CAAA,CAAC,CAAC,OAAF,CAAnB,GAAgC,CAAhC,CADF;OAAA;AAEA,MAAA,IAAG,MAAA,CAAA,CAAQ,CAAC,SAAT,KAAsB,QAAtB,IAAmC,CAAC,CAAC,OAAF,KAAe,IAAC,CAAA,SAAD,CAAA,CAArD;AAIE,QAAA,IAAG,CAAC,CAAC,SAAF,KAAe,IAAC,CAAA,iBAAkB,CAAA,CAAC,CAAC,OAAF,CAArC;AACE,UAAA,IAAC,CAAA,iBAAkB,CAAA,CAAC,CAAC,OAAF,CAAnB,EAAA,CAAA;AACA;iBAAM;;;sBAAN,GAAA;AACE,0BAAA,IAAC,CAAA,iBAAkB,CAAA,CAAC,CAAC,OAAF,CAAnB,GAAA,CADF;UAAA,CAAA;0BAFF;SAJF;OAHY;IAAA,CAlJd,CAAA;;yBAAA;;MARF,CAAA;;AAAA,EA2KA,MAAM,CAAC,OAAP,GAAiB,aA3KjB,CAAA;AAAA","file":"HistoryBuffer.js","sourceRoot":"/source/","sourcesContent":["\n#\n# @nodoc\n# An object that holds all applied operations.\n#\n# @note The HistoryBuffer is commonly abbreviated to HB.\n#\nclass HistoryBuffer\n\n\n\n #\n # Creates an empty HB.\n # @param {Object} user_id Creator of the HB.\n #\n constructor: (@user_id)->\n @operation_counter = {}\n @buffer = {}\n @change_listeners = []\n @garbage = [] # Will be cleaned on next call of garbageCollector\n @trash = [] # Is deleted. Wait until it is not used anymore.\n @performGarbageCollection = true\n @garbageCollectTimeout = 1000\n @reserved_identifier_counter = 0\n setTimeout @emptyGarbage, @garbageCollectTimeout\n\n emptyGarbage: ()=>\n for o in @garbage\n #if @getOperationCounter(o.creator) > o.op_number\n o.cleanup?()\n\n @garbage = @trash\n @trash = []\n if @garbageCollectTimeout isnt -1\n @garbageCollectTimeoutId = setTimeout @emptyGarbage, @garbageCollectTimeout\n undefined\n\n #\n # Get the user id with wich the History Buffer was initialized.\n #\n getUserId: ()->\n @user_id\n\n addToGarbageCollector: ()->\n if @performGarbageCollection\n for o in arguments\n if o?\n @garbage.push o\n\n stopGarbageCollection: ()->\n @performGarbageCollection = false\n @setManualGarbageCollect()\n @garbage = []\n @trash = []\n\n setManualGarbageCollect: ()->\n @garbageCollectTimeout = -1\n clearTimeout @garbageCollectTimeoutId\n @garbageCollectTimeoutId = undefined\n\n setGarbageCollectTimeout: (@garbageCollectTimeout)->\n\n #\n # I propose to use it in your Framework, to create something like a root element.\n # An operation with this identifier is not propagated to other clients.\n # This is why everybode must create the same operation with this uid.\n #\n getReservedUniqueIdentifier: ()->\n {\n creator : '_'\n op_number : \"_#{@reserved_identifier_counter++}\"\n doSync: false\n }\n\n #\n # Get the operation counter that describes the current state of the document.\n #\n getOperationCounter: (user_id)->\n if not user_id?\n res = {}\n for user,ctn of @operation_counter\n res[user] = ctn\n res\n else\n @operation_counter[user_id]\n\n\n #\n # Encode this operation in such a way that it can be parsed by remote peers.\n # TODO: Make this more efficient!\n _encode: (state_vector={})->\n json = []\n unknown = (user, o_number)->\n if (not user?) or (not o_number?)\n throw new Error \"dah!\"\n not state_vector[user]? or state_vector[user] <= o_number\n\n for u_name,user of @buffer\n for o_number,o of user\n if o.doSync and unknown(u_name, o_number)\n # its necessary to send it, and not known in state_vector\n o_json = o._encode()\n if o.next_cl? # applies for all ops but the most right delimiter!\n # search for the next _known_ operation. (When state_vector is {} then this is the Delimiter)\n o_next = o.next_cl\n while o_next.next_cl? and unknown(o_next.creator, o_next.op_number)\n o_next = o_next.next_cl\n o_json.next = o_next.getUid()\n else if o.prev_cl? # most right delimiter only!\n # same as the above with prev.\n o_prev = o.prev_cl\n while o_prev.prev_cl? and unknown(o_prev.creator, o_prev.op_number)\n o_prev = o_prev.prev_cl\n o_json.prev = o_prev.getUid()\n json.push o_json\n\n json\n\n #\n # Get the number of operations that were created by a user.\n # Accordingly you will get the next operation number that is expected from that user.\n # This will increment the operation counter.\n #\n getNextOperationIdentifier: (user_id)->\n if not user_id?\n user_id = @user_id\n if not @operation_counter[user_id]?\n @operation_counter[user_id] = 0\n uid =\n 'creator' : user_id\n 'op_number' : @operation_counter[user_id]\n @operation_counter[user_id]++\n uid\n\n #\n # Retrieve an operation from a unique id.\n #\n getOperation: (uid)->\n if uid instanceof Object\n @buffer[uid.creator]?[uid.op_number]\n else if not uid?\n else\n throw new Error \"This type of uid is not defined!\"\n #\n # Add an operation to the HB. Note that this will not link it against\n # other operations (it wont executed)\n #\n addOperation: (o)->\n if not @buffer[o.creator]?\n @buffer[o.creator] = {}\n if @buffer[o.creator][o.op_number]?\n throw new Error \"You must not overwrite operations!\"\n @buffer[o.creator][o.op_number] = o\n o\n\n removeOperation: (o)->\n delete @buffer[o.creator]?[o.op_number]\n\n #\n # Increment the operation_counter that defines the current state of the Engine.\n #\n addToCounter: (o)->\n if not @operation_counter[o.creator]?\n @operation_counter[o.creator] = 0\n if typeof o.op_number is 'number' and o.creator isnt @getUserId()\n # TODO: fix this issue better.\n # Operations should income in order\n # Then you don't have to do this..\n if o.op_number is @operation_counter[o.creator]\n @operation_counter[o.creator]++\n while @getOperation({creator:o.creator, op_number: @operation_counter[o.creator]})?\n @operation_counter[o.creator]++\n\n #if @operation_counter[o.creator] isnt (o.op_number + 1)\n #console.log (@operation_counter[o.creator] - (o.op_number + 1))\n #console.log o\n #throw new Error \"You don't receive operations in the proper order. Try counting like this 0,1,2,3,4,.. ;)\"\n\nmodule.exports = HistoryBuffer\n"]}
|
|
=======
|
|
{"version":3,"sources":["H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,CAAR,GAAqB,EAArB,CADF;OAAA;AAEA,MAAA,IAAG,2CAAH;AACE,cAAU,IAAA,KAAA,CAAM,oCAAN,CAAV,CADF;OAFA;AAAA,MAIA,IAAC,CAAA,MAAO,CAAA,CAAC,CAAC,OAAF,CAAW,CAAA,CAAC,CAAC,SAAF,CAAnB,GAAkC,CAJlC,CAAA;aAKA,EANY;IAAA,CA3Id,CAAA;;AAAA,4BAmJA,eAAA,GAAiB,SAAC,CAAD,GAAA;AACf,UAAA,IAAA;uDAAA,MAAA,CAAA,IAA2B,CAAA,CAAC,CAAC,SAAF,WADZ;IAAA,CAnJjB,CAAA;;AAAA,4BAyJA,YAAA,GAAc,SAAC,CAAD,GAAA;AACZ,UAAA,QAAA;AAAA,MAAA,IAAO,yCAAP;AACE,QAAA,IAAC,CAAA,iBAAkB,CAAA,CAAC,CAAC,OAAF,CAAnB,GAAgC,CAAhC,CADF;OAAA;AAEA,MAAA,IAAG,MAAA,CAAA,CAAQ,CAAC,SAAT,KAAsB,QAAtB,IAAmC,CAAC,CAAC,OAAF,KAAe,IAAC,CAAA,SAAD,CAAA,CAArD;AAIE,QAAA,IAAG,CAAC,CAAC,SAAF,KAAe,IAAC,CAAA,iBAAkB,CAAA,CAAC,CAAC,OAAF,CAArC;AACE,UAAA,IAAC,CAAA,iBAAkB,CAAA,CAAC,CAAC,OAAF,CAAnB,EAAA,CAAA;AACA;iBAAM;;;sBAAN,GAAA;AACE,0BAAA,IAAC,CAAA,iBAAkB,CAAA,CAAC,CAAC,OAAF,CAAnB,GAAA,CADF;UAAA,CAAA;0BAFF;SAJF;OAHY;IAAA,CAzJd,CAAA;;yBAAA;;MARF,CAAA;;AAAA,EAkLA,MAAM,CAAC,OAAP,GAAiB,aAlLjB,CAAA;AAAA","file":"HistoryBuffer.js","sourceRoot":"/source/","sourcesContent":["\n#\n# @nodoc\n# An object that holds all applied operations.\n#\n# @note The HistoryBuffer is commonly abbreviated to HB.\n#\nclass HistoryBuffer\n\n\n\n #\n # Creates an empty HB.\n # @param {Object} user_id Creator of the HB.\n #\n constructor: (@user_id)->\n @operation_counter = {}\n @buffer = {}\n @change_listeners = []\n @garbage = [] # Will be cleaned on next call of garbageCollector\n @trash = [] # Is deleted. Wait until it is not used anymore.\n @performGarbageCollection = true\n @garbageCollectTimeout = 1000\n @reserved_identifier_counter = 0\n setTimeout @emptyGarbage, @garbageCollectTimeout\n\n emptyGarbage: ()=>\n for o in @garbage\n #if @getOperationCounter(o.creator) > o.op_number\n o.cleanup?()\n\n @garbage = @trash\n @trash = []\n if @garbageCollectTimeout isnt -1\n @garbageCollectTimeoutId = setTimeout @emptyGarbage, @garbageCollectTimeout\n undefined\n\n #\n # Get the user id with wich the History Buffer was initialized.\n #\n getUserId: ()->\n @user_id\n\n addToGarbageCollector: ()->\n if @performGarbageCollection\n for o in arguments\n if o?\n @garbage.push o\n\n stopGarbageCollection: ()->\n @performGarbageCollection = false\n @setManualGarbageCollect()\n @garbage = []\n @trash = []\n\n setManualGarbageCollect: ()->\n @garbageCollectTimeout = -1\n clearTimeout @garbageCollectTimeoutId\n @garbageCollectTimeoutId = undefined\n\n setGarbageCollectTimeout: (@garbageCollectTimeout)->\n\n #\n # I propose to use it in your Framework, to create something like a root element.\n # An operation with this identifier is not propagated to other clients.\n # This is why everybode must create the same operation with this uid.\n #\n getReservedUniqueIdentifier: ()->\n {\n creator : '_'\n op_number : \"_#{@reserved_identifier_counter++}\"\n }\n\n #\n # Get the operation counter that describes the current state of the document.\n #\n getOperationCounter: (user_id)->\n if not user_id?\n res = {}\n for user,ctn of @operation_counter\n res[user] = ctn\n res\n else\n @operation_counter[user_id]\n \n\n renewOperationCounter: (state_vector)->\n for key,value of state_vector\n if @operation_counter[key] < value\n @operation_counter[key] = value\n undefined\n \n\n\n #\n # Encode this operation in such a way that it can be parsed by remote peers.\n # TODO: Make this more efficient!\n _encode: (state_vector={})->\n json = []\n unknown = (user, o_number)->\n if (not user?) or (not o_number?)\n throw new Error \"dah!\"\n not state_vector[user]? or state_vector[user] <= o_number\n\n for u_name,user of @buffer\n for o_number,o of user\n if o.doSync and unknown(u_name, o_number)\n # its necessary to send it, and not known in state_vector\n o_json = o._encode()\n if o.next_cl? # applies for all ops but the most right delimiter!\n # search for the next _known_ operation. (When state_vector is {} then this is the Delimiter)\n o_next = o.next_cl\n while o_next.next_cl? and unknown(o_next.creator, o_next.op_number)\n o_next = o_next.next_cl\n o_json.next = o_next.getUid()\n else if o.prev_cl? # most right delimiter only!\n # same as the above with prev.\n o_prev = o.prev_cl\n while o_prev.prev_cl? and unknown(o_prev.creator, o_prev.op_number)\n o_prev = o_prev.prev_cl\n o_json.prev = o_prev.getUid()\n json.push o_json\n\n json\n\n #\n # Get the number of operations that were created by a user.\n # Accordingly you will get the next operation number that is expected from that user.\n # This will increment the operation counter.\n #\n getNextOperationIdentifier: (user_id)->\n if not user_id?\n user_id = @user_id\n if not @operation_counter[user_id]?\n @operation_counter[user_id] = 0\n uid =\n 'creator' : user_id\n 'op_number' : @operation_counter[user_id]\n @operation_counter[user_id]++\n uid\n\n #\n # Retrieve an operation from a unique id.\n #\n getOperation: (uid)->\n if uid instanceof Object\n @buffer[uid.creator]?[uid.op_number]\n else if not uid?\n else\n throw new Error \"This type of uid is not defined!\"\n #\n # Add an operation to the HB. Note that this will not link it against\n # other operations (it wont executed)\n #\n addOperation: (o)->\n if not @buffer[o.creator]?\n @buffer[o.creator] = {}\n if @buffer[o.creator][o.op_number]?\n throw new Error \"You must not overwrite operations!\"\n @buffer[o.creator][o.op_number] = o\n o\n\n removeOperation: (o)->\n delete @buffer[o.creator]?[o.op_number]\n\n #\n # Increment the operation_counter that defines the current state of the Engine.\n #\n addToCounter: (o)->\n if not @operation_counter[o.creator]?\n @operation_counter[o.creator] = 0\n if typeof o.op_number is 'number' and o.creator isnt @getUserId()\n # TODO: fix this issue better.\n # Operations should income in order\n # Then you don't have to do this..\n if o.op_number is @operation_counter[o.creator]\n @operation_counter[o.creator]++\n while @getOperation({creator:o.creator, op_number: @operation_counter[o.creator]})?\n @operation_counter[o.creator]++\n\n #if @operation_counter[o.creator] isnt (o.op_number + 1)\n #console.log (@operation_counter[o.creator] - (o.op_number + 1))\n #console.log o\n #throw new Error \"You don't receive operations in the proper order. Try counting like this 0,1,2,3,4,.. ;)\"\n\nmodule.exports = HistoryBuffer\n"]}
|
|
>>>>>>> 4da6efd63496589d52de8ca453ead78a804f44e4
|