MotionScript

@motion-script/core


@motion-script/core / Signal

Class: Signal<T>

Defined in: signals/signal.ts:40

Reactive cell that stores a value and tracks dependencies.

A cell can be a plain value (set/get) or bound to a computation fn. Reads during a bound fn's execution are recorded as dependencies; when any dep is set, the cell is marked dirty and recomputes lazily on next read.

Subscribers fire only when the cell's value actually changes. Bound cells without listeners stay lazy — they recompute on the next read. Bound cells with listeners recompute eagerly when dirtied so subscribers can be notified with a fresh value.

Type Parameters

T

T

Constructors

Constructor

new Signal<T>(initial): Signal<T>

Defined in: signals/signal.ts:63

Parameters

initial

T | (() => T)

Returns

Signal<T>

Properties

owner

owner: SignalOwner | null = null

Defined in: signals/signal.ts:61

Internal

Methods

bind()

bind(fn): void

Defined in: signals/signal.ts:105

Parameters

fn

() => T

Returns

void


dispose()

dispose(): void

Defined in: signals/signal.ts:134

Permanently severs all graph edges and releases closures.

  • Upstream: removes this cell from every dep's _subs (same as unbind).
  • Downstream: removes this cell from every subscriber's _deps so they stop tracking it, then clears _subs.
  • External: clears all _listeners so subscriber callbacks are released.

After dispose() the cell is inert. Do not read or write it.

Returns

void


get()

get(): T

Defined in: signals/signal.ts:73

Returns

T


isBound()

isBound(): boolean

Defined in: signals/signal.ts:146

Returns

boolean


peek()

peek(): T

Defined in: signals/signal.ts:88

Returns

T


restoreFrom()

restoreFrom(snap): void

Defined in: signals/signal.ts:170

Reapply a snapshot taken by snapshot. A bound snapshot re-binds the recorded computation; a plain snapshot sets the recorded value. Used by node restore() to roll a cell back to a saved state.

Parameters

snap

SignalSnapshot<T>

Returns

void


set()

set(value): void

Defined in: signals/signal.ts:93

Parameters

value

T

Returns

void


snapshot()

snapshot(): SignalSnapshot<T>

Defined in: signals/signal.ts:159

Capture this cell's current reactive state so it can be reapplied later with restoreFrom — the backing primitive for node save().

A bound cell records its computation fn (so the binding, not just its resolved value, is preserved); a plain cell records its value. Reading is done via peek, so taking a snapshot never creates a tracking dependency on this cell.

Returns

SignalSnapshot<T>


subscribe()

subscribe(fn): Unsubscribe

Defined in: signals/signal.ts:175

Parameters

fn

Subscriber<T>

Returns

Unsubscribe


unbind()

unbind(): void

Defined in: signals/signal.ts:120

Returns

void