UseViewOptions interface

Module @runic-artifex/svelte in @runic-artifex/svelte 0.23.0

interface UseViewOptions<TClient extends ViewClient>

Connects a generated View reference while the calling component is mounted and exposes its state as reactive properties. Call it during component initialization with a getter, such as useView(() => page), so a changed prop releases the previous client and connects the new one. A released client stays connected for keepAlive milliseconds (2000 by default), and the next useView of the same reference takes it over: an {#if} that toggles, HMR and A→B→A navigation show the View at once. A reference is identified by its connect function, so a getter returning a new { connect: connectShell } object does not reconnect.

Properties

release

readonly release?: (client: TClient) => void;

Releases a client this helper connected. Defaults to client.dispose().

keepAlive

readonly keepAlive?: number;

Milliseconds a client this helper connected stays connected after the component unmounts or the source changes, for the next helper that follows the same reference (StrictMode, HMR, <Activity>, A→B→A navigation). 0 disposes it at once. Defaults to 2000. Read once, when the helper is created.