MCPcopy
hub / github.com/tldraw/tldraw / Store

Class Store

packages/store/src/lib/Store.ts:340–1281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

338 * @public
339 */
340export class Store<R extends UnknownRecord = UnknownRecord, Props = unknown> {
341 /**
342 * The unique identifier of the store instance.
343 *
344 * @public
345 */
346 public readonly id: string
347 /**
348 * An AtomMap containing the stores records.
349 *
350 * @internal
351 * @readonly
352 */
353 private readonly records: AtomMap<IdOf<R>, R>
354
355 /**
356 * An atom containing the store's history.
357 *
358 * @public
359 * @readonly
360 */
361 readonly history: Atom<number, RecordsDiff<R>> = atom('history', 0, {
362 historyLength: 1000,
363 })
364
365 /**
366 * Reactive queries and indexes for efficiently accessing store data.
367 * Provides methods for filtering, indexing, and subscribing to subsets of records.
368 *
369 * @example
370 * ```ts
371 * // Create an index by a property
372 * const booksByAuthor = store.query.index('book', 'author')
373 *
374 * // Get records matching criteria
375 * const inStockBooks = store.query.records('book', () => ({
376 * inStock: { eq: true }
377 * }))
378 * ```
379 *
380 * @public
381 * @readonly
382 */
383 readonly query: StoreQueries<R>
384
385 /**
386 * A set containing listeners that have been added to this store.
387 *
388 * @internal
389 */
390 private listeners = new Set<{ onHistory: StoreListener<R>; filters: StoreListenerFilters }>()
391
392 /**
393 * An array of history entries that have not yet been flushed.
394 *
395 * @internal
396 */
397 private historyAccumulator = new HistoryAccumulator<R>()

Callers

nothing calls this directly

Calls 1

atomFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…