Create Structs based on offset, if necessary

implement offset parameter in Ref.toStruct
This commit is contained in:
Kevin Jahns
2019-04-05 12:38:02 +02:00
parent e56899a02c
commit 8a7416ad50
15 changed files with 234 additions and 74 deletions

View File

@@ -8,6 +8,8 @@ import {
getItemCleanEnd,
getItemCleanStart,
getItemType,
ItemDeleted,
GC,
Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
@@ -71,17 +73,32 @@ export class ItemFormatRef extends AbstractItemRef {
}
/**
* @param {Transaction} transaction
* @return {ItemFormat}
* @param {number} offset
* @return {ItemFormat|GC}
*/
toStruct (transaction) {
toStruct (transaction, offset) {
const y = transaction.y
const store = y.store
let parent
if (this.parent !== null) {
const parentItem = getItemType(store, this.parent)
switch (parentItem.constructor) {
case ItemDeleted:
case GC:
return new GC(this.id, 1)
}
parent = parentItem.type
} else {
// @ts-ignore
parent = y.get(this.parentYKey)
}
return new ItemFormat(
this.id,
this.left === null ? null : getItemCleanEnd(store, transaction, this.left),
this.right === null ? null : getItemCleanStart(store, transaction, this.right),
// @ts-ignore
this.parent === null ? y.get(this.parentYKey) : getItemType(store, this.parent).type,
parent,
this.parentSub,
this.key,
this.value