API reference › @evolu/svelte › ownerSyncStatusState

Call Signature

function ownerSyncStatusState<
  S extends Readonly<
    Record<string, Readonly<Record<string, AnyStandardSchemaV1>>>
  >,
>(
  evolu: AppOwnerEvolu<S>,
  syncState: ReadonlyStore<SyncState | null>,
): {
  status: OwnerSyncStatus;
};

Defined in: index.svelte.ts:453

Follows 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.

It creates an $effect, so call it where Svelte allows one, such as during component initialization or inside $effect.root. It stops following the store when that component or root is destroyed.

Example

Runes such as $state work only in Svelte components and .svelte.ts or .svelte.js modules. A component calls syncLabelState during its initialization.

import {
  assertType,
  type AppOwnerEvolu,
  type OwnerSyncStatus,
  type ReadonlyStore,
  type SyncState,
  type TestEvoluSchema,
} from "@evolu/common";
import { ownerSyncStatusState } from "@evolu/svelte";

const syncLabelState = (
  evolu: AppOwnerEvolu<TestEvoluSchema>,
  syncState: ReadonlyStore<SyncState | null>,
) => {
  const sync = ownerSyncStatusState(evolu, syncState);
  const label = $derived(sync.status.type);
  return { label: () => label };
};

assertType<
  ReturnType<ReturnType<typeof syncLabelState>["label"]>,
  OwnerSyncStatus["type"]
>();

Call Signature

function ownerSyncStatusState<
  S extends Readonly<
    Record<string, Readonly<Record<string, AnyStandardSchemaV1>>>
  >,
>(
  evolu: DeviceEvolu<S>,
  syncState: ReadonlyStore<SyncState | null>,
  observedOwner: () => ReadonlyOwner | Owner | null,
): {
  status: OwnerSyncStatus;
};

Defined in: index.svelte.ts:458

For the owner ownerSync takes, or null while there is none.