API reference › @evolu/svelte

Interfaces

InterfaceDescription
EvoluAppStateWhat evoluAppState returns, whose properties update when the app changes. It has no device schema, because the device database's instance is EvoluApp.device.
QueryStateWhat queryState returns, whose properties update when the query or its rows change.

Variables

VariableDescription
evoluSvelteDeps-

Functions

FunctionDescription
evoluAppStateFollows an EvoluApp and returns an object whose properties update when it changes: state, the AppOwner this tab has open as an AppOwnerState, and appOwners, the AppOwners the app can open on this device. While state is Open, its evolu is the AppOwner's instance; it changes when the tab opens another AppOwner, or the AppOwner again after a removal and restore or its database's deletion, so key the children that use it with it, which remounts them, and pass it to queryState. While state is None, show a choice such as to open one of appOwners, create one, or restore one. The device database's instance is EvoluApp.device.
ownerSyncUses an owner for sync through Evolu.useOwner while the component or root that calls it lives, and stops when it's destroyed or when the owner that observedOwner returns, or the transports that observedTransports returns, change. Without transports, the owner syncs with the transports of the instance's config. A null owner uses none, for a component that waits for one. The owner and transports are compared by content, so recreating them, such as in a $derived, keeps the same registration. Evolu.deleteOwner of the owner ends its use, and it uses the owner again only once the component mounts again or the owner or transports change. An instance whose database was deleted uses none.
ownerSyncStatusStateFollows the OwnerSyncStatus of an owner in the database of evolu, read from syncState, the SyncStateDep.syncState store of the deps the instance was created with, such as evoluSvelteDeps, and returns an object whose status updates when the status changes, not with every snapshot. Without observedOwner, it is the status of Evolu.appOwner. Otherwise observedOwner returns the owner ownerSync takes; a null owner, for a component that waits for one, gives NoRelays. Before the first snapshot, during server rendering, and until its effect runs, the status is NoRelays. A status keeps its object while it is unchanged. See OwnerSyncStatus for what to show.
queryStateLoads and subscribes to the query that observedQuery returns, and returns a QueryState, whose rows update when the data changes and whose loaded is the current query's first load. A component renders {#await todos.loaded}, what shows while the query loads, {:then}, the rows of todos.rows, {:catch error}, the failure, {/await}, so it tells a loading query from an empty one and shows a failure. See Evolu.loadQuery. It takes any instance, such as an AppOwner's from evoluAppState or the device database's, EvoluApp.device.
storeStateFollows an Evolu ReadonlyStore, such as evoluError or syncState of evoluSvelteDeps, and returns an object whose current is the store's value and updates when it changes. It's what React's useSyncExternalStore does for a store, and current follows Svelte's fromStore. The first render and server rendering read the store once; the effect reads it again once subscribed, so a change since then shows. A store replaces its value rather than mutating it, so current changes only when the value does.