LiveQuery
The reactive primitive that keeps query results in sync with $state.
How it works
LiveQuery<T> is a class that wraps an async query function and automatically re-executes it whenever the underlying store data changes. It uses Svelte 5 $state runes internally, so any component reading .current will re-render when the data updates. The ChangeNotifier system uses microtask batching, so multiple rapid mutations result in a single re-query.
Properties
| Name | Type | Description |
|---|---|---|
current | T | The current query result (reactive via $state) |
loading | boolean | True while the query is executing |
error | Error | null | The last error, or null if successful |
Methods
| Name | Type | Description |
|---|---|---|
refresh() | Promise<void> | Manually re-execute the query |
destroy() | void | Unsubscribe from change notifications and stop updating |
Loading and error states
states.svelte
Reactive store methods
ReactiveStore provides three convenience methods that return LiveQuery instances.
| Name | Type | Description |
|---|---|---|
liveAll() | ILiveQuery<T[]> | Live query for all records — updates on any mutation |
liveGet(key) | ILiveQuery<T | undefined> | Live query for a single record by key |
liveCount() | ILiveQuery<number> | Live count of records in the store |