implement some of the commented todos

This commit is contained in:
Kevin Jahns
2019-04-09 04:01:37 +02:00
parent 1b06f59d1c
commit 52ec698635
24 changed files with 233 additions and 243 deletions

View File

@@ -29,14 +29,11 @@ import * as binary from 'lib0/binary.js'
/**
* Split leftItem into two items
* @param {StructStore} store
* @param {AbstractItem} leftItem
* @param {number} diff
* @return {AbstractItem}
*
* @todo remove store param0
*/
export const splitItem = (store, leftItem, diff) => {
export const splitItem = (leftItem, diff) => {
const id = leftItem.id
// create rightItem
const rightItem = leftItem.copy(
@@ -182,7 +179,7 @@ export class AbstractItem extends AbstractStruct {
if (o.id.client < id.client) {
this.left = o
conflictingItems.clear()
} // TODO: verify break else?
}
} else if (o.origin !== null && itemsBeforeOrigin.has(getItem(store, o.origin))) {
// case 2
if (o.origin === null || !conflictingItems.has(getItem(store, o.origin))) {
@@ -192,9 +189,6 @@ export class AbstractItem extends AbstractStruct {
} else {
break
}
// TODO: experiment with rightOrigin.
// Then you could basically omit conflictingItems!
// Note: you probably can't use right_origin in every case.. only when setting _left
o = o.right
}
// reconnect left/right + update parent map/start if necessary
@@ -340,8 +334,6 @@ export class AbstractItem extends AbstractStruct {
/**
* Computes the last content address of this Item.
* TODO: do still need this?
* @private
*/
get lastId () {
return createID(this.id.client, this.id.clock + this.length - 1)
@@ -378,11 +370,10 @@ export class AbstractItem extends AbstractStruct {
*
* This method should only be cally by StructStore.
*
* @param {StructStore} store
* @param {number} diff
* @return {AbstractItem}
*/
splitAt (store, diff) {
splitAt (diff) {
throw new Error('unimplemented')
}

View File

@@ -14,7 +14,6 @@ import * as encoding from 'lib0/encoding.js'
export const structGCRefNumber = 0
// TODO should have the same base class as Item
export class GC extends AbstractStruct {
/**
* @param {ID} id

View File

@@ -2,8 +2,6 @@
* @module structs
*/
// TODO: ItemBinary should be able to merge with right (similar to other items). Or the other items (ItemJSON) should not be able to merge - extra byte + consistency
import {
AbstractItem,
AbstractItemRef,

View File

@@ -2,8 +2,6 @@
* @module structs
*/
// TODO: ItemBinary should be able to merge with right (similar to other items). Or the other items (ItemJSON) should not be able to merge - extra byte + consistency
import {
AbstractItem,
AbstractItemRef,
@@ -59,15 +57,14 @@ export class ItemDeleted extends AbstractItem {
addToDeleteSet(transaction.deleteSet, this.id, this.length)
}
/**
* @param {StructStore} store
* @param {number} diff
*/
splitAt (store, diff) {
splitAt (diff) {
/**
* @type {ItemDeleted}
*/
// @ts-ignore
const right = splitItem(store, this, diff)
const right = splitItem(this, diff)
right._len -= diff
this._len = diff
return right

View File

@@ -54,15 +54,14 @@ export class ItemJSON extends AbstractItem {
return this.content
}
/**
* @param {StructStore} store
* @param {number} diff
*/
splitAt (store, diff) {
splitAt (diff) {
/**
* @type {ItemJSON}
*/
// @ts-ignore
const right = splitItem(store, this, diff)
const right = splitItem(this, diff)
right.content = this.content.splice(diff)
return right
}

View File

@@ -15,7 +15,7 @@ import * as encoding from 'lib0/encoding.js'
import * as decoding from 'lib0/decoding.js'
export const structStringRefNumber = 6
// TODO: we can probably try to omit rightOrigin. We can just use .right
export class ItemString extends AbstractItem {
/**
* @param {ID} id
@@ -53,16 +53,15 @@ export class ItemString extends AbstractItem {
return this.string.length
}
/**
* @param {StructStore} store
* @param {number} diff
* @return {ItemString}
*/
splitAt (store, diff) {
splitAt (diff) {
/**
* @type {ItemString}
*/
// @ts-ignore
const right = splitItem(store, this, diff)
const right = splitItem(this, diff)
right.string = this.string.slice(diff)
this.string = this.string.slice(0, diff)
return right

View File

@@ -15,7 +15,7 @@ import {
readYXmlFragment,
readYXmlHook,
readYXmlText,
StructStore, Y, GC, ItemDeleted, Transaction, ID, AbstractType // eslint-disable-line
StructStore, Y, GC, Transaction, ID, AbstractType // eslint-disable-line
} from '../internals.js'
import * as encoding from 'lib0/encoding.js' // eslint-disable-line
@@ -83,7 +83,7 @@ export class ItemType extends AbstractItem {
* @param {ID | null} rightOrigin
* @param {AbstractType<any>} parent
* @param {string | null} parentSub
* @return {AbstractItem} TODO, returns itemtype
* @return {ItemType}
*/
copy (id, left, origin, right, rightOrigin, parent, parentSub) {
return new ItemType(id, left, origin, right, rightOrigin, parent, parentSub, this.type._copy())