fixed part of split/merge logic
This commit is contained in:
@@ -189,13 +189,11 @@ export const readDeleteSet = (decoder, transaction, store) => {
|
||||
* @type {AbstractItem}
|
||||
*/
|
||||
// @ts-ignore
|
||||
let struct = structs[index++]
|
||||
if (!struct.deleted) {
|
||||
if (struct.id.clock < clock) {
|
||||
struct = struct.splitAt(store, clock - struct.id.clock)
|
||||
structs.splice(index, 0, struct)
|
||||
}
|
||||
struct.delete(transaction)
|
||||
let struct = structs[index]
|
||||
// split the first item if necessary
|
||||
if (!struct.deleted && struct.id.clock < clock) {
|
||||
structs.splice(index + 1, 0, struct.splitAt(store, clock - struct.id.clock))
|
||||
index++ // increase we now want to use the next struct
|
||||
}
|
||||
while (index < structs.length) {
|
||||
// @ts-ignore
|
||||
|
||||
@@ -98,7 +98,7 @@ export const addStruct = (store, struct) => {
|
||||
*/
|
||||
export const findIndexSS = (structs, clock) => {
|
||||
let left = 0
|
||||
let right = structs.length
|
||||
let right = structs.length - 1
|
||||
while (left <= right) {
|
||||
const midindex = math.floor((left + right) / 2)
|
||||
const mid = structs[midindex]
|
||||
@@ -112,6 +112,8 @@ export const findIndexSS = (structs, clock) => {
|
||||
right = midindex - 1
|
||||
}
|
||||
}
|
||||
// Always check state before looking for a struct in StructStore
|
||||
// Therefore the case of not finding a struct is unexpected
|
||||
throw error.unexpectedCase()
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ export class Y extends Observable {
|
||||
* other peers.
|
||||
*
|
||||
* @param {function(Transaction):void} f The function that should be executed as a transaction
|
||||
*
|
||||
* @todo separate this into a separate function
|
||||
*/
|
||||
transact (f) {
|
||||
let initialCall = false
|
||||
|
||||
@@ -226,6 +226,9 @@ const execStructReaders = (transaction, store, localState, structReaders, stack)
|
||||
}
|
||||
}
|
||||
}
|
||||
if (stack.length > 0) {
|
||||
store.pendingStructReaders.add({ stack, structReaders, missing: stack[stack.length - 1].id })
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user