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AAF,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,CAvGd,CAAA;;yBAAA;;MANF,CAAA;;AAAA,EA8HA,MAAM,CAAC,OAAP,GAAiB,aA9HjB,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 # 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\n #\n # Get the user id with wich the History Buffer was initialized.\n #\n getUserId: ()->\n @user_id\n\n #\n # There is only one reserved unique identifier (uid), so use it wisely.\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 : '_'\n }\n\n #\n # Get the operation counter that describes the current state of the document.\n #\n getOperationCounter: ()->\n res = {}\n for user,ctn of @operation_counter\n res[user] = ctn\n res\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 (not isNaN(parseInt(o_number))) 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?\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?\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 #\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"]}