fixed YArray

This commit is contained in:
Kevin Jahns
2019-03-29 01:02:44 +01:00
parent d9ab593b07
commit ff981a8697
25 changed files with 761 additions and 780 deletions

View File

@@ -2,7 +2,8 @@
* @module structs
*/
import { AbstractItem, logItemHelper, AbstractItemRef } from './AbstractItem.js'
import { AbstractType } from '../types/AbstractType.js' // eslint-disable-line
import { AbstractItem, AbstractItemRef } from './AbstractItem.js'
import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
import { Y } from '../utils/Y.js' // eslint-disable-line
@@ -18,7 +19,7 @@ export class ItemFormat extends AbstractItem {
* @param {ID} id
* @param {AbstractItem | null} left
* @param {AbstractItem | null} right
* @param {ItemType | null} parent
* @param {AbstractType} parent
* @param {string | null} parentSub
* @param {string} key
* @param {any} value
@@ -32,25 +33,13 @@ export class ItemFormat extends AbstractItem {
* @param {ID} id
* @param {AbstractItem | null} left
* @param {AbstractItem | null} right
* @param {ItemType | null} parent
* @param {AbstractType} parent
* @param {string | null} parentSub
*/
copy (id, left, right, parent, parentSub) {
return new ItemFormat(id, left, right, parent, parentSub, this.key, this.value)
}
/**
* Transform this Type to a readable format.
* Useful for logging as all Items and Delete implement this method.
*
* @private
*/
logString () {
return logItemHelper('ItemFormat', this, `key:${JSON.stringify(this.key)},value:${JSON.stringify(this.value)}`)
}
get _length () {
return 1
}
get _countable () {
get countable () {
return false
}
/**
@@ -81,12 +70,14 @@ export class ItemFormatRef extends AbstractItemRef {
* @return {ItemFormat}
*/
toStruct (transaction) {
const store = transaction.y.store
const y = transaction.y
const store = y.store
return new ItemFormat(
this.id,
this.left === null ? null : getItemCleanEnd(store, transaction, this.left),
this.right === null ? null : getItemCleanStart(store, transaction, this.right),
this.parent === null ? null : getItemType(store, this.parent),
// @ts-ignore
this.parent === null ? y.get(this.parentYKey) : getItemType(store, this.parent),
this.parentSub,
this.key,
this.value