Signals: toSignal adapter
Interfaces
Section titled “Interfaces”ISignal
Section titled “ISignal”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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T |
Methods
Section titled “Methods”get():
T
Defined in: src/signals/to-signal.ts:14
Returns the latest selector value. See toSignal.
Returns
Section titled “Returns”T
Functions
Section titled “Functions”toSignal()
Section titled “toSignal()”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
Example
Section titled “Example”import { toSignal } from '@sandlada/document-context'
const countSignal = toSignal(session, (s: { count: number }) => s.count)console.log(countSignal.get())References
Section titled “References”ISession
Section titled “ISession”Re-exports ISession