Skip to content

StoreRegistry

Defined in: livestore/dist/store/StoreRegistry.d.ts:75

Store Registry coordinating store loading, caching, and retention

new StoreRegistry(config?): StoreRegistry

Defined in: livestore/dist/store/StoreRegistry.d.ts:90

Creates a new StoreRegistry instance.

StoreRegistryConfig

StoreRegistry

const registry = new StoreRegistry({
defaultOptions: {
batchUpdates,
unusedCacheTime: 30_000,
}
})

getOrLoad: <TSchema, TContext, TSyncPayloadSchema>(options) => Effect<Store<TSchema, TContext>, UnknownError, Scope>

Defined in: livestore/dist/store/StoreRegistry.d.ts:105

Gets a cached store or loads a new one, with the store lifetime scoped to the caller.

TSchema extends LiveStoreSchema<DbSchema, EventDefRecord>

The schema type for the store

TContext = { }

The context type for the store

TSyncPayloadSchema extends Schema<any, any, never> = Schema<JsonValue, JsonValue, never>

The sync payload schema type

RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>

Effect<Store<TSchema, TContext>, UnknownError, Scope>

An Effect that yields the store, scoped to the provided Scope

  • Stores are kept in cache and reused while any scope holds them
  • When the scope closes, the reference is released; the store is disposed after unusedCacheTime if no other scopes retain it
  • Concurrent calls with the same storeId share the same store instance

getOrLoadPromise: <TSchema, TContext, TSyncPayloadSchema>(options) => Store<TSchema, TContext> | Promise<Store<TSchema, TContext>>

Defined in: livestore/dist/store/StoreRegistry.d.ts:122

Get or load a store, returning it directly if already loaded or a promise if loading.

TSchema extends LiveStoreSchema<DbSchema, EventDefRecord>

The schema type for the store

TContext = { }

The context type for the store

TSyncPayloadSchema extends Schema<any, any, never> = Schema<JsonValue, JsonValue, never>

The sync payload schema type

RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>

Store<TSchema, TContext> | Promise<Store<TSchema, TContext>>

The loaded store if available, or a Promise that resolves to the loaded store

unknown - store loading error

  • Returns the store instance directly (synchronous) when already loaded
  • Returns a stable Promise reference when loading is in progress or needs to be initiated
  • Throws with the same error instance on subsequent calls after failure
  • Applies default options from registry config, with call-site options taking precedence
  • Concurrent calls with the same storeId share the same store instance

preload: <TSchema, TContext, TSyncPayloadSchema>(options) => Promise<void>

Defined in: livestore/dist/store/StoreRegistry.d.ts:150

Loads a store (without suspending) to warm up the cache.

TSchema extends LiveStoreSchema<DbSchema, EventDefRecord>

The schema of the store to preload

TContext = { }

The context type for the store

TSyncPayloadSchema extends Schema<any, any, never> = Schema<JsonValue, JsonValue, never>

The sync payload schema type

RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>

Promise<void>

A promise that resolves when the loading is complete (success or failure)

  • We don’t return the store or throw as this is a fire-and-forget operation.
  • If the entry remains unused after preload resolves/rejects, it is scheduled for disposal.
  • Does not affect the retention of the store in cache.

retain: <TSchema, TContext, TSyncPayloadSchema>(options) => () => void

Defined in: livestore/dist/store/StoreRegistry.d.ts:136

Retains the store in cache.

TSchema extends LiveStoreSchema<DbSchema, EventDefRecord>

The schema type for the store

TContext = { }

The context type for the store

TSyncPayloadSchema extends Schema<any, any, never> = Schema<JsonValue, JsonValue, never>

The sync payload schema type

RegistryStoreOptions<TSchema, TContext, TSyncPayloadSchema>

A release function that, when called, removes this retention hold

(): void

void

  • Multiple retains on the same store are independent; each must be released separately
  • If the store isn’t cached yet, it will be loaded and then retained
  • The store will remain in cache until all retains are released and after unusedCacheTime expires