fix remaining random tests

This commit is contained in:
Kevin Jahns
2019-04-09 00:31:17 +02:00
parent e1a9f314a7
commit 12bcc4d080
11 changed files with 153 additions and 137 deletions

View File

@@ -421,15 +421,16 @@ export class AbstractItem extends AbstractStruct {
}
/**
* @param {Y} y
* @param {Transaction} transaction
* @param {StructStore} store
*/
gcChildren (y) {}
gcChildren (transaction, store) { }
/**
* @param {Y} y
* @return {GC|ItemDeleted}
* @param {Transaction} transaction
* @param {StructStore} store
*/
gc (y) {
gc (transaction, store) {
let r
if (this.parent._item !== null && this.parent._item.deleted) {
r = new GC(this.id, this.length)
@@ -449,8 +450,8 @@ export class AbstractItem extends AbstractStruct {
}
}
}
replaceStruct(y.store, this, r)
return r
replaceStruct(store, this, r)
transaction._replacedItems.add(r)
}
/**
@@ -584,6 +585,10 @@ export const changeItemRefOffset = (item, offset) => {
*/
export const computeItemParams = (y, store, leftid, rightid, parentid, parentSub, parentYKey) => {
const left = leftid === null ? null : getItemCleanEnd(store, leftid)
if (left !== null && left.constructor !== GC && left.right !== null && left.right.id.client === left.id.client && left.right.id.clock === left.id.clock + left.length) {
// we split a merged op, we may need to merge it again after the transaction
y.transaction._replacedItems.add(left)
}
const right = rightid === null ? null : getItemCleanStart(store, rightid)
let parent = null
if (parentid !== null) {

View File

@@ -5,7 +5,6 @@ import {
AbstractRef,
AbstractStruct,
createID,
writeID,
addStruct,
Y, StructStore, Transaction, ID // eslint-disable-line
} from '../internals.js'
@@ -58,12 +57,7 @@ export class GC extends AbstractStruct {
*/
write (encoder, offset) {
encoding.writeUint8(encoder, structGCRefNumber)
if (offset === 0) {
writeID(encoder, this.id)
} else {
writeID(encoder, createID(this.id.client, this.id.clock + offset))
}
encoding.writeVarUint(encoder, this._len)
encoding.writeVarUint(encoder, this._len - offset)
}
}

View File

@@ -22,12 +22,13 @@ import * as encoding from 'lib0/encoding.js' // eslint-disable-line
import * as decoding from 'lib0/decoding.js'
/**
* @param {Y} y
* @param {Transaction} transaction
* @param {StructStore} store
* @param {AbstractItem | null} item
*/
const gcChildren = (y, item) => {
const gcChildren = (transaction, store, item) => {
while (item !== null) {
item.gc(y)
item.gc(transaction, store)
item = item.right
}
}
@@ -109,7 +110,6 @@ export class ItemType extends AbstractItem {
* @private
*/
delete (transaction) {
const y = transaction.y
super.delete(transaction)
transaction.changed.delete(this.type)
transaction.changedParentTypes.delete(this.type)
@@ -128,29 +128,30 @@ export class ItemType extends AbstractItem {
t = t.right
}
if (gcChildren) {
this.gcChildren(y)
this.gcChildren(transaction, transaction.y.store)
}
}
/**
* @param {Y} y
* @param {Transaction} transaction
* @param {StructStore} store
*/
gcChildren (y) {
gcChildren(y, this.type._start)
gcChildren (transaction, store) {
gcChildren(transaction, store, this.type._start)
this.type._start = null
this.type._map.forEach(item => {
gcChildren(y, item)
gcChildren(transaction, store, item)
})
this._map = new Map()
}
/**
* @param {Y} y
* @return {ItemDeleted|GC}
* @param {Transaction} transaction
* @param {StructStore} store
*/
gc (y) {
this.gcChildren(y)
return super.gc(y)
gc (transaction, store) {
super.gc(transaction, store)
this.gcChildren(transaction, store)
}
}