Skip to content

Signals: toSignal adapter

Defined in: src/signals/to-signal.ts:13

Minimal TC39 Signal-compatible view over a session selector.

Exposes only get(): T; the object is not itself reactive. Framework signal integrations poll or wrap get() in their own tracking scope.

Type Parameter
T

get(): T

Defined in: src/signals/to-signal.ts:14

Returns the latest selector value. See toSignal.

T

Adapts select(selector)(session) into a pull-based signal object.

Captures the current selector value immediately, then keeps it fresh via an internal subscribe() feed that re-runs selector on every state change. The subscription is intentionally retained for the session lifetime (no unsubscribe is returned), so prefer one signal per long-lived view rather than per render. Selectors must stay pure; disposed sessions freeze the last value instead of updating.

export function toSignal<S extends Record<PropertyKey, any>, R>(
session: ISession<S, any>,
selector: (state: S) => R
): ISignal<R>;

Defined in: src/signals/to-signal.ts

import { toSignal } from '@sandlada/document-context'
const countSignal = toSignal(session, (s: { count: number }) => s.count)
console.log(countSignal.get())

Re-exports ISession