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.
- Introduction — what the TypeScript target is, and how to read the rest of this section.
- Capabilities — which high-level features are possible, built in or through a library.
- Example — a full program using every keyword, and the TypeScript it renders to.
- Naming considerations — how Program's dotted names are carried into TypeScript.
- Entry point — starting a program and attaching it to a root element.
- Drivers — the native drivers that provide the interface, animation and network.
- Runtime — the Reactive and Context machinery the rendered code links against.
- Native modules — the hand-written JavaScript behind
NATIVEfunctions. - Keywords — how each of Program's keywords renders to TypeScript.
- Project setup — the files and commands to build and run the rendered program.
- Reserved words — the words TypeScript keeps for itself, and how a colliding name is escaped.
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.