@bigbluebutton/store

中文文档
2.0.0-alpha.36发布于 2026/09/17Apache-2.0TypeScriptCommonJS近 30 天下载 7156

BigBlueButton's fork of tldraw 2.0-alpha.19 - A tiny little drawing app (store).

原始使用文档
文档目录34 节
  1. RecordStore
  2. put(records: R[]): void
  3. update(id: ID<R>, updater: (record: R) => R): void
  4. remove(ids: ID<R>[]): void
  5. get(id: ID<R>): R
  6. allRecords(): R[]
  7. clear(): void
  8. has(id: ID<R>): boolean
  9. serialize(filter?: (record: R) => boolean): RecordStoreSnap…
  10. deserialize(snapshot: RecordStoreSnapshot<R>): void
  11. listen(listener: ((entry: HistoryEntry) => void): () => void
  12. mergeRemoteChanges(fn: () => void): void
  13. createDerivationCache(name: string, derive: ((record: R) =>…
  14. RecordType
  15. create(properties: Pick<R, RequiredProperties> & Omit<Parti…
  16. clone(record: R): R
  17. createId(): ID<R>
  18. createCustomId(id: string): ID<R>
  19. isInstance
  20. isId
  21. withDefaultProperties
  22. RecordStoreQueries
  23. Helpers
  24. executeQuery
  25. DerivationCache
  26. createRecordType
  27. assertIdType
  28. Types
  29. ID
  30. BaseRecord
  31. AllRecords
  32. RecordsDiff
  33. CollectionDiff
  34. License

@bigbluebutton/tlstore

tlstore is a library for creating and managing data.

In this library, a "record" is an object that is stored under a typed id.

tlstore is used by tldraw to store its data.

It is designed to be used with tlstate (@bigbluebutton/tlstate).

Usage

First create types for your records.

interface Book extends BaseRecord<'book'> {
    title: string
    author: ID<Author>
    numPages: number
}

interface Author extends BaseRecord<'author'> {
    name: string
    isPseudonym: boolean
}

Then create your RecordType instances.

const Book = createRecordType<Book>('book')

const Author = createRecordType<Author>('author').withDefaultProperties(() => ({
    isPseudonym: false,
}))

Then create your RecordStore instance.

const store = new RecordStore<Book | Author>()

Then you can create records, add them to the store, update, and remove them.

const tolkeinId = Author.createCustomId('tolkein')

store.put([
    Author.create({
        id: jrrTolkeinId,
        name: 'J.R.R Tolkein',
    }),
])

store.update(tolkeinId, (author) => ({
    ...author,
    name: 'DJJ Tolkz',
    isPseudonym: true,
}))

store.remove(tolkeinId)

API

RecordStore

The RecordStore class is the main class of the library.

const store = new RecordStore()

put(records: R[]): void

Add some records to the store. It's an error if they already exist.

const record = Author.create({
    name: 'J.R.R Tolkein',
    id: Author.createCustomId('tolkein'),
})

store.put([record])

update(id: ID<R>, updater: (record: R) => R): void

Update a record. To update multiple records at once, use the update method of the TypedRecordStore class.

const id = Author.createCustomId('tolkein')

store.update(id, (r) => ({ ...r, name: 'Jimmy Tolks' }))

remove(ids: ID<R>[]): void

Remove some records from the store via their ids.

const id = Author.createCustomId('tolkein')

store.remove([id])

get(id: ID<R>): R

Get the value of a store record by its id.

const id = Author.createCustomId('tolkein')

const result = store.get(id)

allRecords(): R[]

Get an array of all values in the store.

const results = store.allRecords()

clear(): void

Remove all records from the store.

store.clear()

has(id: ID<R>): boolean

Get whether the record store has an record stored under the given id.

const id = Author.createCustomId('tolkein')

const result = store.has(id)

serialize(filter?: (record: R) => boolean): RecordStoreSnapshot<R>

Opposite of deserialize. Creates a JSON payload from the record store.

const serialized = store.serialize()
const serialized = store.serialize((record) => record.name === 'J.R.R Tolkein')

deserialize(snapshot: RecordStoreSnapshot<R>): void

Opposite of serialize. Replace the store's current records with records as defined by a simple JSON structure into the stores.

const serialized = { ... }

store.deserialize(serialized)

listen(listener: ((entry: HistoryEntry) => void): () => void

Add a new listener to the store The store will call the function each time the history changes. Returns a function to remove the listener.

store.listen((entry) => doSomethingWith(entry))

mergeRemoteChanges(fn: () => void): void

Merge changes from a remote source without triggering listeners.

store.mergeRemoteChanges(() => {
    store.put(recordsFromRemoteSource)
})

createDerivationCache(name: string, derive: ((record: R) => R | undefined)): DerivationCache<R>

Create a new derivation cache.

const derivationCache = createDerivationCache('popular_authors', (record) => {
    return record.popularity > 62 ? record : undefined
})

RecordType

The RecordType class is used to define the structure of a record.

const recordType = new RecordType('author', () => ({ living: true }))

RecordType instances are most often created with createRecordType.

create(properties: Pick<R, RequiredProperties> & Omit<Partial<R>, RequiredProperties>): R

Create a new record of this type.

const record = recordType.create({ name: 'J.R.R Tolkein' })

clone(record: R): R

Clone a record of this type.

const record = recordType.create({ name: 'J.R.R Tolkein' })

const clone = recordType.clone(record)

createId(): ID<R>

Create an Id for a record of this type.

const id = recordType.createId()

createCustomId(id: string): ID<R>

Create a custom Id for a record of this type.

const id = recordType.createCustomId('tolkein')

isInstance

Check if a value is an instance of this record type.

const record = recordType.create({ name: 'J.R.R Tolkein' })

const result1 = recordType.isInstance(record) // true
const result2 = recordType.isInstance(someOtherRecord) // false

isId

Check if a value is an id for a record of this type.

const id = recordType.createCustomId('tolkein')

const result1 = recordType.isId(id) // true
const result2 = recordType.isId(someOtherId) // false

withDefaultProperties

Create a new record type with default properties.

const youngLivingAuthor = new RecordType('author', () => ({ age: 28, living: true }))

const oldDeadAuthor = recordType.withDefaultProperties({ age: 93, living: false })

RecordStoreQueries

TODO

Helpers

executeQuery

TODO

DerivationCache

The DerivationCache class is used to create a cache of derived records.

const derivationCache = new DerivationCache('popular_authors', (record) => {
    return record.popularity > 62 ? record : undefined
})

createRecordType

A helper used to create a new RecordType instance with no default properties.

const recordType = createRecordType('author'))

assertIdType

A helper used to assert that a value is an id for a record of a given type.

const id = recordType.createCustomId('tolkein')

assertIdType(id, recordType)

Types

ID

A type used to represent a record's id.

const id: ID<Author> = Author.createCustomId('tolkein')

BaseRecord

A BaseRecord is a record that has an id and a type. It is the base type for all records.

type AuthorRecord extends BaseRecord<"author"> {
  name: string
  age: number
  living: boolean
}

AllRecords

A helper to get the type of all records in a record store.

type AllAuthorRecords = AllRecords<RecordStore<Author>>

RecordsDiff

A diff describing the changes to a record.

CollectionDiff

A diff describing the changes to a collection.

License

The source code in this repository (as well as our 2.0+ distributions and releases) are currently licensed under Apache-2.0. These licenses are subject to change in our upcoming 2.0 release. If you are planning to use tldraw in a commercial product, please reach out at [email protected].

版本与发布记录

@bigbluebutton/store 共发布 13 个版本,首次发布于 2024/05/23;过去 12 个月发布了 5 个版本。

版本发布日期距今
2.0.0-alpha.36latest2026/09/171 个月前
2.0.0-alpha.352026/05/215 个月前
2.0.0-alpha.342026/05/165 个月前
2.0.0-alpha.332026/01/229 个月前
2.0.0-alpha.322026/01/159 个月前
2.0.0-alpha.312025/09/221.1 年前

关于 @bigbluebutton/store 的常见问题

@bigbluebutton/store 是什么?

BigBlueButton's fork of tldraw 2.0-alpha.19 - A tiny little drawing app (store).

如何安装 @bigbluebutton/store?

在项目目录运行 npm install @bigbluebutton/store,或使用 pnpm add / yarn add / bun add。

@bigbluebutton/store 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@bigbluebutton/store 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bigbluebutton/store 可以商用吗?

@bigbluebutton/store 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@bigbluebutton/store 的下载量有多少?

根据 npm 官方下载统计,@bigbluebutton/store 在 2026/10/08 – 2026/11/06 这 30 天内被下载 7,156 次,日均约 239 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@bigbluebutton/store 还在维护吗?

最新版本 2.0.0-alpha.36 发布于 2026/09/17(1 个月前);至今共发布 13 个版本,其中过去 12 个月发布了 5 个;首次发布于 2024/05/23。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。