/
dimamir
/
yjs
Обзор
Документация
Войти
/
dimamir
/
yjs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/structs/ContentAny.js
114 строк
2 KB
Kevin Jahns
[#667] sanity checks for Yjs caveats. In dev_mode, objects inserted into Yjs can't be manipulated.
04 окт 2024, 22:23
04 окт 2024, 22:23
8152cf8
Код
Авторство
О чём код?
import { UpdateEncoderV1, UpdateEncoderV2, UpdateDecoderV1, UpdateDecoderV2, Transaction, Item, StructStore // eslint-disable-line } from '../internals.js' import * as env from 'lib0/environment' import * as object from 'lib0/object' const isDevMode = env.getVariable('node_env') === 'development' export class ContentAny { /** * @param {Array<any>} arr */ constructor (arr) { /** * @type {Array<any>} */ this.arr = arr isDevMode && object.deepFreeze(arr) } /** * @return {number} */ getLength () { return this.arr.length } /** * @return {Array<any>} */ getContent () { return this.arr } /** * @return {boolean} */ isCountable () { return true } /** * @return {ContentAny} */ copy () { return new ContentAny(this.arr) } /** * @param {number} offset * @return {ContentAny} */ splice (offset) { const right = new ContentAny(this.arr.slice(offset)) this.arr = this.arr.slice(0, offset) return right } /** * @param {ContentAny} right * @return {boolean} */ mergeWith (right) { this.arr = this.arr.concat(right.arr) return true } /** * @param {Transaction} transaction * @param {Item} item */ integrate (transaction, item) {} /** * @param {Transaction} transaction */ delete (transaction) {} /** * @param {StructStore} store */ gc (store) {} /** * @param {UpdateEncoderV1 | UpdateEncoderV2} encoder * @param {number} offset */ write (encoder, offset) { const len = this.arr.length encoder.writeLen(len - offset) for (let i = offset; i < len; i++) { const c = this.arr[i] encoder.writeAny(c) } } /** * @return {number} */ getRef () { return 8 } } /** * @param {UpdateDecoderV1 | UpdateDecoderV2} decoder * @return {ContentAny} */ export const readContentAny = decoder => { const len = decoder.readLen() const cs = [] for (let i = 0; i < len; i++) { cs.push(decoder.readAny()) } return new ContentAny(cs) }