fix gc when item is deleted in observer call

This commit is contained in:
Kevin Jahns
2019-04-26 18:37:38 +02:00
parent a336cc167c
commit 8c5a06bbf8
12 changed files with 73 additions and 40 deletions

View File

@@ -421,13 +421,14 @@ export class AbstractItem extends AbstractStruct {
/**
* @param {Transaction} transaction
* @param {StructStore} store
* @param {boolean} parentGCd
*
* @private
*/
gc (transaction, store) {
gc (transaction, store, parentGCd) {
this.delete(transaction)
let r
if (this.parent._item !== null && this.parent._item.deleted) {
if (parentGCd) {
r = new GC(this.id, this.length)
} else {
r = new ItemDeleted(this.id, this.left, this.origin, this.right, this.rightOrigin, this.parent, this.parentSub, this.length)

View File

@@ -85,6 +85,19 @@ export class ItemDeleted extends AbstractItem {
}
return false
}
/**
* @param {Transaction} transaction
* @param {StructStore} store
* @param {boolean} parentGCd
*
* @private
*/
gc (transaction, store, parentGCd) {
if (parentGCd) {
super.gc(transaction, store, parentGCd)
}
}
/**
* @param {encoding.Encoder} encoder
* @param {number} offset

View File

@@ -124,13 +124,13 @@ export class ItemType extends AbstractItem {
gcChildren (transaction, store) {
let item = this.type._start
while (item !== null) {
item.gc(transaction, store)
item.gc(transaction, store, true)
item = item.right
}
this.type._start = null
this.type._map.forEach(item => {
while (item !== null) {
item.gc(transaction, store)
item.gc(transaction, store, true)
// @ts-ignore
item = item.left
}
@@ -141,10 +141,11 @@ export class ItemType extends AbstractItem {
/**
* @param {Transaction} transaction
* @param {StructStore} store
* @param {boolean} parentGCd
*/
gc (transaction, store) {
gc (transaction, store, parentGCd) {
this.gcChildren(transaction, store)
super.gc(transaction, store)
super.gc(transaction, store, parentGCd)
}
}