1 line
5.2 KiB
Plaintext
Executable File
1 line
5.2 KiB
Plaintext
Executable File
{"version":3,"file":"HistoryBuffer.js","sources":["HistoryBuffer.coffee"],"names":[],"mappings":"CAMA,WAAA,GAAA,EAAM,GAAA,WAMS,QAAA,GAAE,GAAD,KAAC,QAAA,EACb,KAAC,qBACD,KAAC,UACD,KAAC,0BAHH,GAAA,UAQA,UAAW,iBACT,MAAC,SATH,EAAA,UAiBA,4BAA6B,kBAEzB,QAAU,IACV,UAAY,MApBhB,EAAA,UA0BA,oBAAqB,WACnB,GAAA,GAAA,EAAA,EAAA,CAAA,MACA,EAAA,KAAA,iBAAA,KAAA,IAAA,UACE,EAAI,GAAQ,QACd,IA9BF,EAAA,UAmCA,QAAS,SAAC,GACR,GAAA,GAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,EAAA,YADQ,MACR,KACA,EAAU,SAAC,EAAM,GACf,GAAQ,MAAA,GAAe,MAAA,EACrB,KAAU,IAAA,OAAM,cACd,OAAA,EAAA,IAAuB,EAAa,IAAS,GAEnD,EAAA,KAAA,MAAA,KAAA,IAAA,GAAA,OACE,KAAA,IAAA,GACE,WAAG,MAAU,SAAS,KAAe,EAAQ,EAAQ,GAArD,CAEE,GADA,EAAS,EAAE,UACR,MAAA,EAAA,QAAH,CAEE,IADA,EAAS,EAAE,QACL,MAAA,EAAA,SAAoB,EAAQ,EAAO,QAAS,EAAO,YACvD,EAAS,EAAO,OAClB,GAAO,KAAO,EAAO,aAClB,IAAG,MAAA,EAAA,QAAH,CAEH,IADA,EAAS,EAAE,QACL,MAAA,EAAA,SAAoB,EAAQ,EAAO,QAAS,EAAO,YACvD,EAAS,EAAO,OAClB,GAAO,KAAO,EAAO,SACvB,EAAK,KAAK,UAEhB,IA1DF,EAAA,UAiEA,2BAA4B,SAAC,GAC3B,GAAA,SAAO,OAAA,IACL,EAAU,KAAC,SACN,MAAA,KAAA,kBAAA,KACL,KAAC,kBAAkB,GAAW,GAChC,GACE,QAAY,EACZ,UAAc,KAAC,kBAAkB,IACnC,KAAC,kBAAkB,KACnB,GA1EF,EAAA,UA+EA,aAAc,SAAC,GACb,GAAA,EAAA,IAAG,YAAe,kDACM,EAAI,WAAJ,MACnB,IAAO,MAAA,EAEV,KAAU,IAAA,OAAM,qCApFpB,EAAA,UAyFA,aAAc,SAAC,GAGb,GAFO,MAAA,KAAA,OAAA,EAAA,WACL,KAAC,OAAO,EAAE,aACT,MAAA,KAAA,OAAA,EAAA,SAAA,EAAA,WACD,KAAU,IAAA,OAAM,4CAClB,MAAC,OAAO,EAAE,SAAS,EAAE,WAAa,EAClC,GA/FF,EAAA,UAoGA,aAAc,SAAC,GAGb,MAFO,OAAA,KAAA,kBAAA,EAAA,WACL,KAAC,kBAAkB,EAAE,SAAW,GACT,gBAAtB,GAAS,WAA0B,EAAE,UAAa,KAAC,YACpD,KAAC,kBAAkB,EAAE,WADvB,aAOJ,OAAO,QAAU","sourcesContent":["\n#\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 #\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 o_json = o._encode()\n if o.next_cl?\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 o_prev = o.prev_cl\n while o_prev.prev_cl? and unknown(o_next.creator, o_next.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 @operation_counter[o.creator]++\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"],"sourceRoot":"/source/"} |