fixed linter errors
This commit is contained in:
parent
10cf4b44f8
commit
d25307c355
@ -8,10 +8,9 @@ import {
|
|||||||
readYXmlFragment,
|
readYXmlFragment,
|
||||||
readYXmlHook,
|
readYXmlHook,
|
||||||
readYXmlText,
|
readYXmlText,
|
||||||
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, Item, YEvent, AbstractType, // eslint-disable-line
|
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, StructStore, Transaction, Item, YEvent, AbstractType, ID, // eslint-disable-line
|
||||||
readYWeakLink,
|
readYWeakLink,
|
||||||
unlinkFrom,
|
unlinkFrom
|
||||||
ID
|
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
import * as error from 'lib0/error'
|
import * as error from 'lib0/error'
|
||||||
@ -113,7 +112,7 @@ export class ContentType {
|
|||||||
if (this.type.constructor === WeakLink) {
|
if (this.type.constructor === WeakLink) {
|
||||||
// when removing weak links, remove references to them
|
// when removing weak links, remove references to them
|
||||||
// from type they're pointing to
|
// from type they're pointing to
|
||||||
const type = /** @type {WeakLink<any>} */ (this.type);
|
const type = /** @type {WeakLink<any>} */ (this.type)
|
||||||
const end = /** @type {ID} */ (type._quoteEnd.item)
|
const end = /** @type {ID} */ (type._quoteEnd.item)
|
||||||
for (let item = type._firstItem; item !== null; item = item.right) {
|
for (let item = type._firstItem; item !== null; item = item.right) {
|
||||||
if (item.linked) {
|
if (item.linked) {
|
||||||
@ -121,7 +120,7 @@ export class ContentType {
|
|||||||
}
|
}
|
||||||
const lastId = item.lastId
|
const lastId = item.lastId
|
||||||
if (lastId.client === end.client && lastId.clock === end.clock) {
|
if (lastId.client === end.client && lastId.clock === end.clock) {
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
type._firstItem = null
|
type._firstItem = null
|
||||||
|
@ -581,7 +581,7 @@ export class Item extends AbstractStruct {
|
|||||||
// notify links about changes
|
// notify links about changes
|
||||||
const linkedBy = transaction.doc.store.linkedBy.get(this)
|
const linkedBy = transaction.doc.store.linkedBy.get(this)
|
||||||
if (linkedBy !== undefined) {
|
if (linkedBy !== undefined) {
|
||||||
for (let link of linkedBy) {
|
for (const link of linkedBy) {
|
||||||
addChangedTypeToTransaction(transaction, link, this.parentSub)
|
addChangedTypeToTransaction(transaction, link, this.parentSub)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -695,7 +695,7 @@ export class Item extends AbstractStruct {
|
|||||||
const allLinks = transaction.doc.store.linkedBy
|
const allLinks = transaction.doc.store.linkedBy
|
||||||
const linkedBy = allLinks.get(this)
|
const linkedBy = allLinks.get(this)
|
||||||
if (linkedBy !== undefined) {
|
if (linkedBy !== undefined) {
|
||||||
for (let link of linkedBy) {
|
for (const link of linkedBy) {
|
||||||
addChangedTypeToTransaction(transaction, link, this.parentSub)
|
addChangedTypeToTransaction(transaction, link, this.parentSub)
|
||||||
}
|
}
|
||||||
allLinks.delete(this)
|
allLinks.delete(this)
|
||||||
|
@ -246,7 +246,7 @@ export const callTypeObservers = (type, transaction, event, visitedLinks = null)
|
|||||||
} else if (type._item.linked) {
|
} else if (type._item.linked) {
|
||||||
const linkedBy = transaction.doc.store.linkedBy.get(type._item)
|
const linkedBy = transaction.doc.store.linkedBy.get(type._item)
|
||||||
if (linkedBy !== undefined) {
|
if (linkedBy !== undefined) {
|
||||||
for (let link of linkedBy) {
|
for (const link of linkedBy) {
|
||||||
if (visitedLinks === null || !visitedLinks.has(link)) {
|
if (visitedLinks === null || !visitedLinks.has(link)) {
|
||||||
visitedLinks = visitedLinks !== null ? visitedLinks : new Set()
|
visitedLinks = visitedLinks !== null ? visitedLinks : new Set()
|
||||||
visitedLinks.add(link)
|
visitedLinks.add(link)
|
||||||
|
@ -16,8 +16,7 @@ import {
|
|||||||
YArrayRefID,
|
YArrayRefID,
|
||||||
callTypeObservers,
|
callTypeObservers,
|
||||||
transact,
|
transact,
|
||||||
ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, // eslint-disable-line
|
ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, YWeakLink, // eslint-disable-line
|
||||||
YWeakLink,
|
|
||||||
arrayWeakLink
|
arrayWeakLink
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
import { typeListSlice } from './AbstractType.js'
|
import { typeListSlice } from './AbstractType.js'
|
||||||
|
@ -14,8 +14,7 @@ import {
|
|||||||
YMapRefID,
|
YMapRefID,
|
||||||
callTypeObservers,
|
callTypeObservers,
|
||||||
transact,
|
transact,
|
||||||
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, // eslint-disable-line
|
UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Transaction, Item, YWeakLink, // eslint-disable-line
|
||||||
YWeakLink,
|
|
||||||
mapWeakLink
|
mapWeakLink
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
|
@ -27,14 +27,13 @@ import {
|
|||||||
typeMapGetAll,
|
typeMapGetAll,
|
||||||
updateMarkerChanges,
|
updateMarkerChanges,
|
||||||
ContentType,
|
ContentType,
|
||||||
ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ID, Doc, Item, Snapshot, Transaction, // eslint-disable-line
|
ArraySearchMarker, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ID, Doc, Item, Snapshot, Transaction, YWeakLink, // eslint-disable-line
|
||||||
quoteText
|
quoteText
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
import * as object from 'lib0/object'
|
import * as object from 'lib0/object'
|
||||||
import * as map from 'lib0/map'
|
import * as map from 'lib0/map'
|
||||||
import * as error from 'lib0/error'
|
import * as error from 'lib0/error'
|
||||||
import { WeakLink } from 'yjs'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {any} a
|
* @param {any} a
|
||||||
@ -1067,7 +1066,7 @@ export class YText extends AbstractType {
|
|||||||
*
|
*
|
||||||
* @param {number} index The index where quoted range should start
|
* @param {number} index The index where quoted range should start
|
||||||
* @param {number} length Number of quoted elements
|
* @param {number} length Number of quoted elements
|
||||||
* @return {WeakLink<string>}
|
* @return {YWeakLink<string>}
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
@ -1263,6 +1262,7 @@ export const rangeDelta = (parent, start, end, snapshot, prevSnapshot, computeYC
|
|||||||
// startOffset represents offset at current block from which we're intersted in picking string
|
// startOffset represents offset at current block from which we're intersted in picking string
|
||||||
// if it's -1 it means, we're out of scope and we should break at this point
|
// if it's -1 it means, we're out of scope and we should break at this point
|
||||||
let startOffset = start === null ? 0 : -1
|
let startOffset = start === null ? 0 : -1
|
||||||
|
// eslint-disable-next-line no-labels
|
||||||
loop: while (n !== null) {
|
loop: while (n !== null) {
|
||||||
if (startOffset < 0 && start !== null) {
|
if (startOffset < 0 && start !== null) {
|
||||||
if (start.client === n.id.client && start.clock >= n.id.clock && start.clock < n.id.clock + n.length) {
|
if (start.client === n.id.client && start.clock >= n.id.clock && start.clock < n.id.clock + n.length) {
|
||||||
@ -1287,7 +1287,7 @@ export const rangeDelta = (parent, start, end, snapshot, prevSnapshot, computeYC
|
|||||||
packStr()
|
packStr()
|
||||||
currentAttributes.delete('ychange')
|
currentAttributes.delete('ychange')
|
||||||
}
|
}
|
||||||
let s = /** @type {ContentString} */ (n.content).str
|
const s = /** @type {ContentString} */ (n.content).str
|
||||||
if (startOffset > 0) {
|
if (startOffset > 0) {
|
||||||
str += s.slice(startOffset)
|
str += s.slice(startOffset)
|
||||||
startOffset = 0
|
startOffset = 0
|
||||||
@ -1296,8 +1296,9 @@ export const rangeDelta = (parent, start, end, snapshot, prevSnapshot, computeYC
|
|||||||
const endOffset = n.id.clock + n.length - end.clock - 1
|
const endOffset = n.id.clock + n.length - end.clock - 1
|
||||||
str += s.slice(0, s.length + endOffset) // scope is negative
|
str += s.slice(0, s.length + endOffset) // scope is negative
|
||||||
packStr()
|
packStr()
|
||||||
|
// eslint-disable-next-line no-labels
|
||||||
break loop
|
break loop
|
||||||
} else if (startOffset == 0) {
|
} else if (startOffset === 0) {
|
||||||
str += s
|
str += s
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
@ -1330,7 +1331,7 @@ export const rangeDelta = (parent, start, end, snapshot, prevSnapshot, computeYC
|
|||||||
}
|
}
|
||||||
} else if (end !== null && end.client === n.id.client && end.clock >= n.id.clock && end.clock < n.id.clock + n.length) {
|
} else if (end !== null && end.client === n.id.client && end.clock >= n.id.clock && end.clock < n.id.clock + n.length) {
|
||||||
// block may not passed visibility check, but we still need to verify boundaries
|
// block may not passed visibility check, but we still need to verify boundaries
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
n = n.right
|
n = n.right
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { decoding, encoding, error } from "lib0"
|
import { decoding, encoding, error } from 'lib0'
|
||||||
import * as map from 'lib0/map'
|
import * as map from 'lib0/map'
|
||||||
import * as set from 'lib0/set'
|
import * as set from 'lib0/set'
|
||||||
import {
|
import {
|
||||||
YEvent, Transaction, ID, GC, AbstractType, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, Doc, Item,
|
YEvent, AbstractType,
|
||||||
transact,
|
transact,
|
||||||
getItemCleanEnd,
|
getItemCleanEnd,
|
||||||
createID,
|
createID,
|
||||||
@ -12,14 +12,13 @@ import {
|
|||||||
writeID,
|
writeID,
|
||||||
readID,
|
readID,
|
||||||
RelativePosition,
|
RelativePosition,
|
||||||
ItemTextListPosition,
|
|
||||||
ContentString,
|
ContentString,
|
||||||
rangeDelta,
|
rangeDelta,
|
||||||
formatXmlString,
|
formatXmlString,
|
||||||
Snapshot,
|
|
||||||
YText,
|
YText,
|
||||||
YXmlText
|
YXmlText,
|
||||||
} from "../internals.js"
|
Transaction, Item, Doc, ID, Snapshot, UpdateDecoderV1, UpdateDecoderV2, UpdateEncoderV1, UpdateEncoderV2, ItemTextListPosition // eslint-disable-line
|
||||||
|
} from '../internals.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @template T extends AbstractType<any>
|
* @template T extends AbstractType<any>
|
||||||
@ -31,6 +30,7 @@ export class YWeakLinkEvent extends YEvent {
|
|||||||
* @param {YWeakLink<T>} ylink The YWeakLink to which this event was propagated to.
|
* @param {YWeakLink<T>} ylink The YWeakLink to which this event was propagated to.
|
||||||
* @param {Transaction} transaction
|
* @param {Transaction} transaction
|
||||||
*/
|
*/
|
||||||
|
// eslint-disable-next-line no-useless-constructor
|
||||||
constructor (ylink, transaction) {
|
constructor (ylink, transaction) {
|
||||||
super(ylink, transaction)
|
super(ylink, transaction)
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ export class YWeakLink extends AbstractType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return undefined;
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,7 +103,7 @@ export class YWeakLink extends AbstractType {
|
|||||||
}
|
}
|
||||||
const lastId = item.lastId
|
const lastId = item.lastId
|
||||||
if (lastId.client === end.client && lastId.clock === end.clock) {
|
if (lastId.client === end.client && lastId.clock === end.clock) {
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
item = item.right
|
item = item.right
|
||||||
}
|
}
|
||||||
@ -139,12 +139,12 @@ export class YWeakLink extends AbstractType {
|
|||||||
|
|
||||||
/** @type {Item|null} */
|
/** @type {Item|null} */
|
||||||
let item = firstItem
|
let item = firstItem
|
||||||
let end = /** @type {ID} */ (this._quoteEnd.item)
|
const end = /** @type {ID} */ (this._quoteEnd.item)
|
||||||
for (;item !== null; item = item.right) {
|
for (;item !== null; item = item.right) {
|
||||||
createLink(transaction, item, this)
|
createLink(transaction, item, this)
|
||||||
const lastId = item.lastId
|
const lastId = item.lastId
|
||||||
if (lastId.client === end.client && lastId.clock === end.clock) {
|
if (lastId.client === end.client && lastId.clock === end.clock) {
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -198,7 +198,7 @@ export class YWeakLink extends AbstractType {
|
|||||||
toString () {
|
toString () {
|
||||||
if (this._firstItem !== null) {
|
if (this._firstItem !== null) {
|
||||||
switch (/** @type {AbstractType<any>} */ (this._firstItem.parent).constructor) {
|
switch (/** @type {AbstractType<any>} */ (this._firstItem.parent).constructor) {
|
||||||
case YText:
|
case YText: {
|
||||||
let str = ''
|
let str = ''
|
||||||
/**
|
/**
|
||||||
* @type {Item|null}
|
* @type {Item|null}
|
||||||
@ -211,12 +211,12 @@ export class YWeakLink extends AbstractType {
|
|||||||
}
|
}
|
||||||
const lastId = n.lastId
|
const lastId = n.lastId
|
||||||
if (lastId.client === end.client && lastId.clock === end.clock) {
|
if (lastId.client === end.client && lastId.clock === end.clock) {
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
n = n.right
|
n = n.right
|
||||||
}
|
}
|
||||||
return str
|
return str
|
||||||
|
}
|
||||||
case YXmlText:
|
case YXmlText:
|
||||||
return this.toDelta().map(delta => formatXmlString(delta)).join('')
|
return this.toDelta().map(delta => formatXmlString(delta)).join('')
|
||||||
}
|
}
|
||||||
@ -243,7 +243,6 @@ export class YWeakLink extends AbstractType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
|
* @param {UpdateDecoderV1 | UpdateDecoderV2} decoder
|
||||||
* @return {YWeakLink<any>}
|
* @return {YWeakLink<any>}
|
||||||
@ -280,7 +279,7 @@ export const arrayWeakLink = (transaction, parent, index, length = 1) => {
|
|||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
startItem = getItemCleanStart(transaction, createID(startItem.id.client, startItem.id.clock + index))
|
startItem = getItemCleanStart(transaction, createID(startItem.id.client, startItem.id.clock + index))
|
||||||
}
|
}
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
index -= startItem.length
|
index -= startItem.length
|
||||||
}
|
}
|
||||||
@ -293,7 +292,7 @@ export const arrayWeakLink = (transaction, parent, index, length = 1) => {
|
|||||||
remaining -= endItem.length
|
remaining -= endItem.length
|
||||||
} else {
|
} else {
|
||||||
endItem = getItemCleanEnd(transaction, transaction.doc.store, createID(endItem.id.client, endItem.id.clock + remaining - 1))
|
endItem = getItemCleanEnd(transaction, transaction.doc.store, createID(endItem.id.client, endItem.id.clock + remaining - 1))
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -308,7 +307,7 @@ export const arrayWeakLink = (transaction, parent, index, length = 1) => {
|
|||||||
createLink(transaction, item, link)
|
createLink(transaction, item, link)
|
||||||
const lastId = item.lastId
|
const lastId = item.lastId
|
||||||
if (lastId.client === end.client && lastId.clock === end.clock) {
|
if (lastId.client === end.client && lastId.clock === end.clock) {
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -350,7 +349,7 @@ export const quoteText = (transaction, parent, pos, length) => {
|
|||||||
createLink(transaction, item, link)
|
createLink(transaction, item, link)
|
||||||
const lastId = item.lastId
|
const lastId = item.lastId
|
||||||
if (lastId.client === end.client && lastId.clock === end.clock) {
|
if (lastId.client === end.client && lastId.clock === end.clock) {
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -438,12 +437,12 @@ export const joinLinkedRange = (transaction, item) => {
|
|||||||
const rightLinks = allLinks.get(/** @type {Item} */ (item.right))
|
const rightLinks = allLinks.get(/** @type {Item} */ (item.right))
|
||||||
if (leftLinks && rightLinks) {
|
if (leftLinks && rightLinks) {
|
||||||
const common = new Set()
|
const common = new Set()
|
||||||
for (let link of leftLinks) {
|
for (const link of leftLinks) {
|
||||||
if (rightLinks.has(link)) {
|
if (rightLinks.has(link)) {
|
||||||
common.add(link)
|
common.add(link)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (common.size != 0) {
|
if (common.size !== 0) {
|
||||||
allLinks.set(item, common)
|
allLinks.set(item, common)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,7 @@
|
|||||||
import {
|
import {
|
||||||
GC,
|
GC,
|
||||||
splitItem,
|
splitItem,
|
||||||
Transaction, ID, Item, DSDecoderV2, // eslint-disable-line
|
Transaction, ID, Item, DSDecoderV2, YWeakLink // eslint-disable-line
|
||||||
YWeakLink
|
|
||||||
} from '../internals.js'
|
} from '../internals.js'
|
||||||
|
|
||||||
import * as math from 'lib0/math'
|
import * as math from 'lib0/math'
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import * as Y from '../src/index.js'
|
import * as Y from '../src/index.js'
|
||||||
import * as t from 'lib0/testing'
|
import * as t from 'lib0/testing'
|
||||||
import { init, compare } from './testHelper.js'
|
import { init } from './testHelper.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
@ -63,11 +63,11 @@ export const testArrayQuoteMultipleElements = tc => {
|
|||||||
const link1 = array1.get(0)
|
const link1 = array1.get(0)
|
||||||
let unquoted = link1.unquote()
|
let unquoted = link1.unquote()
|
||||||
t.compare(unquoted[0], 2)
|
t.compare(unquoted[0], 2)
|
||||||
t.compare(unquoted[1].toJSON(), {'key':'value'})
|
t.compare(unquoted[1].toJSON(), { key: 'value' })
|
||||||
t.compare(unquoted[2], 3)
|
t.compare(unquoted[2], 3)
|
||||||
t.compare(array1.get(1), 1)
|
t.compare(array1.get(1), 1)
|
||||||
t.compare(array1.get(2), 2)
|
t.compare(array1.get(2), 2)
|
||||||
t.compare(array1.get(3).toJSON(), {'key':'value'})
|
t.compare(array1.get(3).toJSON(), { key: 'value' })
|
||||||
t.compare(array1.get(4), 3)
|
t.compare(array1.get(4), 3)
|
||||||
|
|
||||||
array1.insert(3, ['A', 'B'])
|
array1.insert(3, ['A', 'B'])
|
||||||
@ -75,7 +75,7 @@ export const testArrayQuoteMultipleElements = tc => {
|
|||||||
t.compare(unquoted[0], 2)
|
t.compare(unquoted[0], 2)
|
||||||
t.compare(unquoted[1], 'A')
|
t.compare(unquoted[1], 'A')
|
||||||
t.compare(unquoted[2], 'B')
|
t.compare(unquoted[2], 'B')
|
||||||
t.compare(unquoted[3].toJSON(), {'key':'value'})
|
t.compare(unquoted[3].toJSON(), { key: 'value' })
|
||||||
t.compare(unquoted[4], 3)
|
t.compare(unquoted[4], 3)
|
||||||
|
|
||||||
testConnector.flushAllMessages()
|
testConnector.flushAllMessages()
|
||||||
@ -102,7 +102,7 @@ export const testSelfQuotation = tc => {
|
|||||||
testConnector.flushAllMessages()
|
testConnector.flushAllMessages()
|
||||||
|
|
||||||
const link1 = array1.get(1)
|
const link1 = array1.get(1)
|
||||||
let unquoted = link1.unquote()
|
const unquoted = link1.unquote()
|
||||||
t.compare(unquoted, [1, link1, 2, 3])
|
t.compare(unquoted, [1, link1, 2, 3])
|
||||||
t.compare(array1.get(0), 1)
|
t.compare(array1.get(0), 1)
|
||||||
t.compare(array1.get(1), link1)
|
t.compare(array1.get(1), link1)
|
||||||
@ -115,7 +115,7 @@ export const testSelfQuotation = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testUpdate = tc => {
|
export const testUpdate = tc => {
|
||||||
const { testConnector, users, map0, map1 } = init(tc, { users: 2 })
|
const { testConnector, map0, map1 } = init(tc, { users: 2 })
|
||||||
map0.set('a', new Y.Map([['a1', 'hello']]))
|
map0.set('a', new Y.Map([['a1', 'hello']]))
|
||||||
const link0 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map0.link('a'))
|
const link0 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map0.link('a'))
|
||||||
map0.set('b', link0)
|
map0.set('b', link0)
|
||||||
@ -139,7 +139,7 @@ export const testUpdate = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testDeleteWeakLink = tc => {
|
export const testDeleteWeakLink = tc => {
|
||||||
const { testConnector, users, map0, map1 } = init(tc, { users: 2 })
|
const { testConnector, map0, map1 } = init(tc, { users: 2 })
|
||||||
map0.set('a', new Y.Map([['a1', 'hello']]))
|
map0.set('a', new Y.Map([['a1', 'hello']]))
|
||||||
const link0 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map0.link('a'))
|
const link0 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map0.link('a'))
|
||||||
map0.set('b', link0)
|
map0.set('b', link0)
|
||||||
@ -164,15 +164,15 @@ export const testDeleteWeakLink = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testDeleteSource = tc => {
|
export const testDeleteSource = tc => {
|
||||||
const { testConnector, users, map0, map1 } = init(tc, { users: 2 })
|
const { testConnector, map0, map1 } = init(tc, { users: 2 })
|
||||||
map0.set('a', new Y.Map([['a1', 'hello']]))
|
map0.set('a', new Y.Map([['a1', 'hello']]))
|
||||||
const link0 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map0.link('a'))
|
const link0 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map0.link('a'))
|
||||||
map0.set('b', link0)
|
map0.set('b', link0)
|
||||||
|
|
||||||
testConnector.flushAllMessages()
|
testConnector.flushAllMessages()
|
||||||
const link1 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map1.get('b'))
|
const link1 = /** @type {Y.WeakLink<Y.Map<any>>} */ (map1.get('b'))
|
||||||
let l1 = /** @type {Y.Map<any>} */ (link1.deref())
|
const l1 = /** @type {Y.Map<any>} */ (link1.deref())
|
||||||
let l0 = /** @type {Y.Map<any>} */ (link0.deref())
|
const l0 = /** @type {Y.Map<any>} */ (link0.deref())
|
||||||
t.compare(l1.get('a1'), l0.get('a1'))
|
t.compare(l1.get('a1'), l0.get('a1'))
|
||||||
|
|
||||||
map1.delete('a') // delete source of the link
|
map1.delete('a') // delete source of the link
|
||||||
@ -188,7 +188,7 @@ export const testDeleteSource = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testObserveMapUpdate = tc => {
|
export const testObserveMapUpdate = tc => {
|
||||||
const { testConnector, users, map0, map1 } = init(tc, { users: 2 })
|
const { testConnector, map0, map1 } = init(tc, { users: 2 })
|
||||||
map0.set('a', 'value')
|
map0.set('a', 'value')
|
||||||
const link0 = /** @type {Y.WeakLink<String>} */ (map0.link('a'))
|
const link0 = /** @type {Y.WeakLink<String>} */ (map0.link('a'))
|
||||||
map0.set('b', link0)
|
map0.set('b', link0)
|
||||||
@ -196,17 +196,21 @@ export const testObserveMapUpdate = tc => {
|
|||||||
* @type {any}
|
* @type {any}
|
||||||
*/
|
*/
|
||||||
let target0
|
let target0
|
||||||
link0.observe((e) => target0 = e.target)
|
link0.observe((e) => {
|
||||||
|
target0 = e.target
|
||||||
|
})
|
||||||
|
|
||||||
testConnector.flushAllMessages()
|
testConnector.flushAllMessages()
|
||||||
|
|
||||||
let link1 = /** @type {Y.WeakLink<String>} */ (map1.get('b'))
|
const link1 = /** @type {Y.WeakLink<String>} */ (map1.get('b'))
|
||||||
t.compare(link1.deref(), 'value')
|
t.compare(link1.deref(), 'value')
|
||||||
/**
|
/**
|
||||||
* @type {any}
|
* @type {any}
|
||||||
*/
|
*/
|
||||||
let target1
|
let target1
|
||||||
link1.observe((e) => target1 = e.target)
|
link1.observe((e) => {
|
||||||
|
target1 = e.target
|
||||||
|
})
|
||||||
|
|
||||||
map0.set('a', 'value2')
|
map0.set('a', 'value2')
|
||||||
t.compare(target0.deref(), 'value2')
|
t.compare(target0.deref(), 'value2')
|
||||||
@ -219,7 +223,7 @@ export const testObserveMapUpdate = tc => {
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testObserveMapDelete = tc => {
|
export const testObserveMapDelete = tc => {
|
||||||
const { testConnector, users, map0, map1 } = init(tc, { users: 2 })
|
const { testConnector, map0, map1 } = init(tc, { users: 2 })
|
||||||
map0.set('a', 'value')
|
map0.set('a', 'value')
|
||||||
const link0 = /** @type {Y.WeakLink<String>} */ (map0.link('a'))
|
const link0 = /** @type {Y.WeakLink<String>} */ (map0.link('a'))
|
||||||
map0.set('b', link0)
|
map0.set('b', link0)
|
||||||
@ -227,17 +231,21 @@ export const testObserveMapDelete = tc => {
|
|||||||
* @type {any}
|
* @type {any}
|
||||||
*/
|
*/
|
||||||
let target0
|
let target0
|
||||||
link0.observe((e) => target0 = e.target)
|
link0.observe((e) => {
|
||||||
|
target0 = e.target
|
||||||
|
})
|
||||||
|
|
||||||
testConnector.flushAllMessages()
|
testConnector.flushAllMessages()
|
||||||
|
|
||||||
let link1 = /** @type {Y.WeakLink<String>} */ (map1.get('b'))
|
const link1 = /** @type {Y.WeakLink<String>} */ (map1.get('b'))
|
||||||
t.compare(link1.deref(), 'value')
|
t.compare(link1.deref(), 'value')
|
||||||
/**
|
/**
|
||||||
* @type {any}
|
* @type {any}
|
||||||
*/
|
*/
|
||||||
let target1
|
let target1
|
||||||
link1.observe((e) => target1 = e.target)
|
link1.observe((e) => {
|
||||||
|
target1 = e.target
|
||||||
|
})
|
||||||
|
|
||||||
map0.delete('a')
|
map0.delete('a')
|
||||||
t.compare(target0.deref(), undefined)
|
t.compare(target0.deref(), undefined)
|
||||||
@ -257,17 +265,21 @@ export const testObserveArray = tc => {
|
|||||||
* @type {any}
|
* @type {any}
|
||||||
*/
|
*/
|
||||||
let target0
|
let target0
|
||||||
link0.observe((e) => target0 = e.target)
|
link0.observe((e) => {
|
||||||
|
target0 = e.target
|
||||||
|
})
|
||||||
|
|
||||||
testConnector.flushAllMessages()
|
testConnector.flushAllMessages()
|
||||||
|
|
||||||
let link1 = /** @type {Y.WeakLink<String>} */ (array1.get(0))
|
const link1 = /** @type {Y.WeakLink<String>} */ (array1.get(0))
|
||||||
t.compare(link1.unquote(), ['B', 'C'])
|
t.compare(link1.unquote(), ['B', 'C'])
|
||||||
/**
|
/**
|
||||||
* @type {any}
|
* @type {any}
|
||||||
*/
|
*/
|
||||||
let target1
|
let target1
|
||||||
link1.observe((e) => target1 = e.target)
|
link1.observe((e) => {
|
||||||
|
target1 = e.target
|
||||||
|
})
|
||||||
|
|
||||||
array0.delete(2)
|
array0.delete(2)
|
||||||
t.compare(target0.unquote(), ['C'])
|
t.compare(target0.unquote(), ['C'])
|
||||||
@ -315,7 +327,9 @@ export const testDeepObserveTransitive = tc => {
|
|||||||
* @type {Array<any>}
|
* @type {Array<any>}
|
||||||
*/
|
*/
|
||||||
let events = []
|
let events = []
|
||||||
link2.observeDeep((e) => events = e)
|
link2.observeDeep((e) => {
|
||||||
|
events = e
|
||||||
|
})
|
||||||
map2.set('key', 'value2')
|
map2.set('key', 'value2')
|
||||||
const values = events.map((e) => e.target.deref())
|
const values = events.map((e) => e.target.deref())
|
||||||
t.compare(values, ['value2'])
|
t.compare(values, ['value2'])
|
||||||
@ -354,7 +368,9 @@ export const testDeepObserveTransitive2 = tc => {
|
|||||||
* @type {Array<any>}
|
* @type {Array<any>}
|
||||||
*/
|
*/
|
||||||
let events = []
|
let events = []
|
||||||
link3.observeDeep((e) => events = e)
|
link3.observeDeep((e) => {
|
||||||
|
events = e
|
||||||
|
})
|
||||||
map2.set('key', 'value2')
|
map2.set('key', 'value2')
|
||||||
const values = events.map((e) => e.target.deref())
|
const values = events.map((e) => e.target.deref())
|
||||||
t.compare(values, ['value2'])
|
t.compare(values, ['value2'])
|
||||||
@ -381,7 +397,9 @@ export const testDeepObserveMap = tc => {
|
|||||||
* @type {Array<any>}
|
* @type {Array<any>}
|
||||||
*/
|
*/
|
||||||
let events = []
|
let events = []
|
||||||
map.observeDeep((e) => events = e)
|
map.observeDeep((e) => {
|
||||||
|
events = e
|
||||||
|
})
|
||||||
|
|
||||||
const nested = new Y.Map()
|
const nested = new Y.Map()
|
||||||
array.insert(0, [nested])
|
array.insert(0, [nested])
|
||||||
@ -436,14 +454,14 @@ export const testDeepObserveArray = tc => { //FIXME
|
|||||||
let events = []
|
let events = []
|
||||||
array.observeDeep((evts) => {
|
array.observeDeep((evts) => {
|
||||||
events = []
|
events = []
|
||||||
for (let e of evts) {
|
for (const e of evts) {
|
||||||
switch (e.constructor) {
|
switch (e.constructor) {
|
||||||
case Y.YMapEvent:
|
case Y.YMapEvent:
|
||||||
events.push({ target: e.target, keys: e.keys })
|
events.push({ target: e.target, keys: e.keys })
|
||||||
break;
|
break
|
||||||
case Y.YWeakLinkEvent:
|
case Y.YWeakLinkEvent:
|
||||||
events.push({ target: e.target })
|
events.push({ target: e.target })
|
||||||
break;
|
break
|
||||||
default: throw new Error('unexpected event type ' + e.constructor)
|
default: throw new Error('unexpected event type ' + e.constructor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -477,7 +495,7 @@ export const testDeepObserveArray = tc => { //FIXME
|
|||||||
* @param {t.TestCase} tc
|
* @param {t.TestCase} tc
|
||||||
*/
|
*/
|
||||||
export const testDeepObserveNewElementWithinQuotedRange = tc => {
|
export const testDeepObserveNewElementWithinQuotedRange = tc => {
|
||||||
const { testConnector, users, array0, array1 } = init(tc, { users: 2 })
|
const { testConnector, array0, array1 } = init(tc, { users: 2 })
|
||||||
const m1 = new Y.Map()
|
const m1 = new Y.Map()
|
||||||
const m3 = new Y.Map()
|
const m3 = new Y.Map()
|
||||||
array0.insert(0, [1, m1, m3, 2])
|
array0.insert(0, [1, m1, m3, 2])
|
||||||
@ -492,14 +510,14 @@ export const testDeepObserveNewElementWithinQuotedRange = tc => {
|
|||||||
let e0 = []
|
let e0 = []
|
||||||
link0.observeDeep((evts) => {
|
link0.observeDeep((evts) => {
|
||||||
e0 = []
|
e0 = []
|
||||||
for (let e of evts) {
|
for (const e of evts) {
|
||||||
switch (e.constructor) {
|
switch (e.constructor) {
|
||||||
case Y.YMapEvent:
|
case Y.YMapEvent:
|
||||||
e0.push({ target: e.target, keys: e.keys })
|
e0.push({ target: e.target, keys: e.keys })
|
||||||
break;
|
break
|
||||||
case Y.YWeakLinkEvent:
|
case Y.YWeakLinkEvent:
|
||||||
e0.push({ target: e.target })
|
e0.push({ target: e.target })
|
||||||
break;
|
break
|
||||||
default: throw new Error('unexpected event type ' + e.constructor)
|
default: throw new Error('unexpected event type ' + e.constructor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -512,14 +530,14 @@ export const testDeepObserveNewElementWithinQuotedRange = tc => {
|
|||||||
let e1 = []
|
let e1 = []
|
||||||
link1.observeDeep((evts) => {
|
link1.observeDeep((evts) => {
|
||||||
e1 = []
|
e1 = []
|
||||||
for (let e of evts) {
|
for (const e of evts) {
|
||||||
switch (e.constructor) {
|
switch (e.constructor) {
|
||||||
case Y.YMapEvent:
|
case Y.YMapEvent:
|
||||||
e1.push({ target: e.target, keys: e.keys })
|
e1.push({ target: e.target, keys: e.keys })
|
||||||
break;
|
break
|
||||||
case Y.YWeakLinkEvent:
|
case Y.YWeakLinkEvent:
|
||||||
e1.push({ target: e.target })
|
e1.push({ target: e.target })
|
||||||
break;
|
break
|
||||||
default: throw new Error('unexpected event type ' + e.constructor)
|
default: throw new Error('unexpected event type ' + e.constructor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -556,20 +574,19 @@ export const testMapDeepObserve = tc => { //FIXME
|
|||||||
let events = []
|
let events = []
|
||||||
outer.observeDeep((evts) => {
|
outer.observeDeep((evts) => {
|
||||||
events = []
|
events = []
|
||||||
for (let e of evts) {
|
for (const e of evts) {
|
||||||
switch (e.constructor) {
|
switch (e.constructor) {
|
||||||
case Y.YMapEvent:
|
case Y.YMapEvent:
|
||||||
events.push({ target: e.target, keys: e.keys })
|
events.push({ target: e.target, keys: e.keys })
|
||||||
break;
|
break
|
||||||
case Y.YWeakLinkEvent:
|
case Y.YWeakLinkEvent:
|
||||||
events.push({ target: e.target })
|
events.push({ target: e.target })
|
||||||
break;
|
break
|
||||||
default: throw new Error('unexpected event type ' + e.constructor)
|
default: throw new Error('unexpected event type ' + e.constructor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
inner.set('key', 'value1')
|
inner.set('key', 'value1')
|
||||||
t.compare(events.length, 1)
|
t.compare(events.length, 1)
|
||||||
t.compare(events[0].target, inner)
|
t.compare(events[0].target, inner)
|
||||||
@ -629,7 +646,9 @@ export const testDeepObserveRecursive = tc => {
|
|||||||
* @type {Array<any>}
|
* @type {Array<any>}
|
||||||
*/
|
*/
|
||||||
let events = []
|
let events = []
|
||||||
m0.observeDeep((e) => events = e)
|
m0.observeDeep((e) => {
|
||||||
|
events = e
|
||||||
|
})
|
||||||
|
|
||||||
m1.set('test-key1', 'value1')
|
m1.set('test-key1', 'value1')
|
||||||
t.compare(events.length, 1)
|
t.compare(events.length, 1)
|
||||||
@ -750,6 +769,6 @@ export const testQuoteFormattedText = tc => {
|
|||||||
t.compare(delta, [
|
t.compare(delta, [
|
||||||
{ insert: l1 },
|
{ insert: l1 },
|
||||||
{ insert: l2 },
|
{ insert: l2 },
|
||||||
{insert: l3},
|
{ insert: l3 }
|
||||||
])
|
])
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user