Reactive Layer

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

NameTypeDescription
current TThe current query result (reactive via $state)
loading booleanTrue while the query is executing
error Error | nullThe last error, or null if successful

Methods

NameTypeDescription
refresh() Promise<void>Manually re-execute the query
destroy() voidUnsubscribe from change notifications and stop updating

Loading and error states

states.svelte

Reactive store methods

ReactiveStore provides three convenience methods that return LiveQuery instances.

NameTypeDescription
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