splitting an item must always happen inside a transaction, because we always need to check if we can merge it back

This commit is contained in:
Kevin Jahns
2019-04-11 00:23:08 +02:00
parent 9fe47e98d5
commit 2ef11a5344
18 changed files with 72 additions and 63 deletions

View File

@@ -193,7 +193,7 @@ export const readDeleteSet = (decoder, transaction, store) => {
let struct = structs[index]
// split the first item if necessary
if (!struct.deleted && struct.id.clock < clock) {
structs.splice(index + 1, 0, struct.splitAt(clock - struct.id.clock))
structs.splice(index + 1, 0, struct.splitAt(transaction, clock - struct.id.clock))
index++ // increase we now want to use the next struct
}
while (index < structs.length) {
@@ -202,7 +202,7 @@ export const readDeleteSet = (decoder, transaction, store) => {
if (struct.id.clock < clock + len) {
if (!struct.deleted) {
if (clock + len < struct.id.clock + struct.length) {
structs.splice(index, 0, struct.splitAt(clock + len - struct.id.clock))
structs.splice(index, 0, struct.splitAt(transaction, clock + len - struct.id.clock))
}
struct.delete(transaction)
}

View File

@@ -2,7 +2,7 @@
import {
GC,
AbstractRef, ID, ItemType, AbstractItem, AbstractStruct // eslint-disable-line
Transaction, AbstractRef, ID, ItemType, AbstractItem, AbstractStruct // eslint-disable-line
} from '../internals.js'
import * as math from 'lib0/math.js'
@@ -167,13 +167,15 @@ export const getItemType = (store, id) => find(store, id)
/**
* Expects that id is actually in store. This function throws or is an infinite loop otherwise.
*
* @param {Transaction} transaction
* @param {StructStore} store
* @param {ID} id
* @return {AbstractItem}
*
* @private
*/
export const getItemCleanStart = (store, id) => {
export const getItemCleanStart = (transaction, store, id) => {
/**
* @type {Array<AbstractItem>}
*/
@@ -185,7 +187,7 @@ export const getItemCleanStart = (store, id) => {
*/
let struct = structs[index]
if (struct.id.clock < id.clock && struct.constructor !== GC) {
struct = struct.splitAt(id.clock - struct.id.clock)
struct = struct.splitAt(transaction, id.clock - struct.id.clock)
structs.splice(index + 1, 0, struct)
}
return struct
@@ -193,13 +195,15 @@ export const getItemCleanStart = (store, id) => {
/**
* Expects that id is actually in store. This function throws or is an infinite loop otherwise.
*
* @param {Transaction} transaction
* @param {StructStore} store
* @param {ID} id
* @return {AbstractItem}
*
* @private
*/
export const getItemCleanEnd = (store, id) => {
export const getItemCleanEnd = (transaction, store, id) => {
/**
* @type {Array<AbstractItem>}
*/
@@ -208,7 +212,7 @@ export const getItemCleanEnd = (store, id) => {
const index = findIndexSS(structs, id.clock)
const struct = structs[index]
if (id.clock !== struct.id.clock + struct.length - 1 && struct.constructor !== GC) {
structs.splice(index + 1, 0, struct.splitAt(id.clock - struct.id.clock + 1))
structs.splice(index + 1, 0, struct.splitAt(transaction, id.clock - struct.id.clock + 1))
}
return struct
}

View File

@@ -170,7 +170,7 @@ export const transact = (y, f) => {
const deleteItem = deleteItems[di]
for (let si = findIndexSS(structs, deleteItem.clock); si < structs.length; si++) {
const struct = structs[si]
if (deleteItem.clock + deleteItem.len < struct.id.clock) {
if (deleteItem.clock + deleteItem.len <= struct.id.clock) {
break
}
if (struct.deleted && struct instanceof AbstractItem && (struct.constructor !== ItemDeleted || (struct.parent._item !== null && struct.parent._item.deleted))) {

View File

@@ -207,7 +207,7 @@ const resumeStructIntegration = (transaction, store) => {
}
if (m.length === 0) {
if (offset < ref.length) {
ref.toStruct(transaction.y, store, offset).integrate(transaction)
ref.toStruct(transaction, store, offset).integrate(transaction)
}
stack.pop()
}