@livestore/svelte package exposes a single helper, createStore, which binds store.query into Svelte’s reactivity system. When you call store.query inside $effect or markup, query results re-run automatically when LiveStore emits updates. Requests are cancelled on teardown via Svelte’s abort signal.
Installation
Setup
Create a worker file
Create a dedicated worker file for the LiveStore web worker:
livestore.worker.ts
Reactive queries
store.query opts into Svelte’s reactivity when called inside $effect or markup. The query result re-evaluates whenever the underlying data changes.
TodoList.svelte
store.subscribe directly for manual subscription management.
Committing events
Callstore.commit() to dispatch events. LiveStore propagates the event to all reactive queries automatically.
TodoInput.svelte
Usage notes
createStoreis async. Await it in a context that supports async initialization — a routeloadfunction,onMount, or a top-level browser module.- Works with the web adapter out of the box.
- For SSR routes, construct the store on the client.
@livestore/adapter-webis browser-only and requires OPFS, which is not available in a server environment.
API reference
createStore<Schema>(options)
Creates and returns a LiveStore instance integrated with Svelte’s reactivity.
| Option | Type | Description |
|---|---|---|
storeId | string | Unique identifier for the store |
schema | Schema | The LiveStore schema |
adapter | Adapter | The platform adapter (e.g., makePersistedAdapter()) |
store.query method.
store.query(queryable)
Executes a reactive query. When called inside $effect or Svelte markup, re-evaluates automatically whenever the underlying data changes. Accepts any Queryable — a QueryBuilder, LiveQueryDef, or SignalDef.