Targets · TypeScript · Runtime

Runtime

The Reactive and Context machinery the rendered code links against.

Contents

How a Program becomes TypeScript, in parts. Start with the introduction, then follow each part into the rendered output and the runtime it links against.

Three parts

The runtime has the same three parts as every target. Reactive holds state and derives values; Context carries emissions out to the drivers; Native is the drivers and the hand-written pieces they are built from. Rendered code names only a thin surface, now fully typed.

Reactive, typed through

A STATE is the one place a value changes; everything else derives from it. In TypeScript the value carries its type as a generic, so the graph type-checks end to end.

const count: ReactiveValue<number> = Reactive.State<number>(0);
const label: ReactiveValue<string> =
  Reactive.Calculate<string>(() => 'Count: ' + Reactive.Value(count));
// a write arrives as Reactive.Set(count, next)

An in-flight or failed value carries a lock — the LOCKED state, a ReactiveValue<T> that may be pending or error — and that lock travels with anything derived from it, so a loader can respond without special-casing.

Context and the cycle

A program does not call the DOM or the network; it emits into named typed channels, and a driver drains each. The interface is a tree channel; most effects are flat lists. The entry point drives one loop per turn: open a channel per active driver, run the reactive program (write-backs then forward), drain, dispatch, then wait. Nothing polls — a cycle happens exactly when a value is written from outside. The runtime ships as one bundle the rendered program links against, with the type declarations included.