From 7fe1b6a8894d4bbcc85b6172f82fea6877c7b60e Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Fri, 11 Aug 2023 10:40:56 -0400 Subject: [PATCH] docs: update jsdoc --- src/structs/GC.js | 10 ++++++++++ src/utils/updates.js | 12 +++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/structs/GC.js b/src/structs/GC.js index 42d71f73..c29ce10d 100644 --- a/src/structs/GC.js +++ b/src/structs/GC.js @@ -11,6 +11,16 @@ export const structGCRefNumber = 0 * @private */ export class GC extends AbstractStruct { + /** + * @param {ID} id + * @param {number} length + */ + constructor (id, length) { + super(id, length) + this.left = null + this.right = null + } + get deleted () { return true } diff --git a/src/utils/updates.js b/src/utils/updates.js index c64ce355..109f63d5 100644 --- a/src/utils/updates.js +++ b/src/utils/updates.js @@ -90,7 +90,7 @@ export class LazyStructReader { constructor (decoder, filterSkips) { this.gen = lazyStructReaderGenerator(decoder) /** - * @type {null | Item | Skip | GC} + * @type {null | Item | GC} */ this.curr = null this.done = false @@ -99,11 +99,12 @@ export class LazyStructReader { } /** - * @return {Item | GC | Skip |null} + * @return {Item | GC |null} */ next () { // ignore "Skip" structs do { + // @ts-ignore this.curr is not `Skip` finally this.curr = this.gen.next().value || null } while (this.filterSkips && this.curr !== null && this.curr.constructor === Skip) return this.curr @@ -297,7 +298,7 @@ export const parseUpdateMeta = update => parseUpdateMetaV2(update, UpdateDecoder * * @param {Item | GC | Skip} left * @param {number} diff - * @return {Item | GC} + * @return {Item | GC | Skip} */ const sliceStruct = (left, diff) => { if (left.constructor === GC) { @@ -378,10 +379,11 @@ export const mergeUpdatesV2 = (updates, YDecoder = UpdateDecoderV2, YEncoder = U const currDecoder = lazyStructDecoders[0] // write from currDecoder until the next operation is from another client or if filler-struct // then we need to reorder the decoders and find the next operation to write + /** @type {number} */ const firstClient = /** @type {Item | GC} */ (currDecoder.curr).id.client if (currWrite !== null) { - let curr = /** @type {Item | GC | null} */ (currDecoder.curr) + let curr = /** @type {Item | GC | Skip | null} */ (currDecoder.curr) let iterated = false // iterate until we find something that we haven't written already @@ -520,7 +522,7 @@ const flushLazyStructWriter = lazyWriter => { /** * @param {LazyStructWriter} lazyWriter - * @param {Item | GC} struct + * @param {Item | GC | Skip} struct * @param {number} offset */ const writeStructToLazyStructWriter = (lazyWriter, struct, offset) => {