fix a few tsc errors (96 remaining)

This commit is contained in:
Kevin Jahns
2019-03-13 02:15:43 +01:00
parent 5a42a94cf4
commit 293527e62b
15 changed files with 63 additions and 86 deletions

View File

@@ -6,7 +6,7 @@ import { Tree } from 'lib0/tree.js'
import * as ID from '../utils/ID.js'
import { getStruct } from './structReferences.js'
import { GC } from '../structs/GC.js'
import * as stringify from './structStringify.js'
import * as Item from '../structs/Item.js'
export class OperationStore extends Tree {
constructor (y) {
@@ -18,18 +18,18 @@ export class OperationStore extends Tree {
this.iterate(null, null, item => {
if (item.constructor === GC) {
items.push({
id: stringify.stringifyItemID(item),
id: Item.stringifyItemID(item),
content: item._length,
deleted: 'GC'
})
} else {
items.push({
id: stringify.stringifyItemID(item),
origin: item._origin === null ? '()' : stringify.stringifyID(item._origin._lastId),
left: item._left === null ? '()' : stringify.stringifyID(item._left._lastId),
right: stringify.stringifyItemID(item._right),
right_origin: stringify.stringifyItemID(item._right_origin),
parent: stringify.stringifyItemID(item._parent),
id: Item.stringifyItemID(item),
origin: item._origin === null ? '()' : Item.stringifyID(item._origin._lastId),
left: item._left === null ? '()' : Item.stringifyID(item._left._lastId),
right: Item.stringifyItemID(item._right),
right_origin: Item.stringifyItemID(item._right_origin),
parent: Item.stringifyItemID(item._parent),
parentSub: item._parentSub,
deleted: item._deleted,
content: JSON.stringify(item._content)

View File

@@ -1,46 +0,0 @@
import * as ID from './ID.js'
/**
* Stringify an item id.
*
* @param {ID.ID | ID.RootID} id
* @return {string}
*/
export const stringifyID = id => id instanceof ID.ID ? `(${id.user},${id.clock})` : `(${id.name},${id.type})`
/**
* Stringify an item as ID. HHere, an item could also be a Yjs instance (e.g. item._parent).
*
* @param {Y.Item | Y.Y | null} item
* @return {string}
*/
export const stringifyItemID = item => {
let result
if (item === null) {
result = '()'
} else if (item._id != null) {
result = stringifyID(item._id)
} else {
// must be a Yjs instance
// Don't include Y in this module, so we prevent circular dependencies.
result = 'y'
}
return result
}
/**
* Helper utility to convert an item to a readable format.
*
* @param {String} name The name of the item class (YText, ItemString, ..).
* @param {Y.Item} item The item instance.
* @param {String} [append] Additional information to append to the returned
* string.
* @return {String} A readable string that represents the item object.
*
*/
export const logItemHelper = (name, item, append) => {
const left = item._left !== null ? stringifyID(item._left._lastId) : '()'
const origin = item._origin !== null ? stringifyID(item._origin._lastId) : '()'
return `${name}(id:${stringifyItemID(item)},left:${left},origin:${origin},right:${stringifyItemID(item._right)},parent:${stringifyItemID(item._parent)},parentSub:${item._parentSub}${append !== undefined ? ' - ' + append : ''})`
}