fixed part of split/merge logic

This commit is contained in:
Kevin Jahns
2019-04-08 13:41:28 +02:00
parent 7a111de186
commit e1a9f314a7
8 changed files with 39 additions and 29 deletions

View File

@@ -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

View File

@@ -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()
}

View File

@@ -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

View File

@@ -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 })
}
}
/**