Entry point | TypeScript | Program targets

Targets · TypeScript · Entry point

Starting a program and attaching it to a root element in the page.

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.

A program starts with a single typed call. It takes the root component — a callback that runs the program — and the array of drivers the embed uses, and returns a cancel function that tears the program down.

The signature is Program.Application(content: () => void, drivers: Driver[]): () => void . Types are carried through the whole call: the root component's reactive values are ReactiveValue<T> , and each driver is checked against the Driver interface, so a mis-wired embed fails to compile rather than at runtime.

The interface is attached to one root element. The DOM interface driver takes that element — by id or as an HTMLElement — owns everything inside it, and patches it in place each cycle.

Many isolated programs can share one page, each mounted into its own node.

The returned cancel stops the cycle, tears down the drivers, and releases the root element — wired to beforeunload for a whole-page app, or called by hand to remove an embed that comes and goes.

Recommended articles