typescript · hud · machines

Machines

hud's outer layer: who runs what, and what crosses between

Boot

What runs in the tab on page load, in order, as built. Served, the tab's document is the server's shell and the page a frame under it: every step runs once for the tab, ⑥ again for each page the frame loads. The server holds nothing for the page until the owner's first thread. The last column is the step as a GenServer: init is everything before the link, the link is one call, and every later frame is handle_info.

step call reads leaves GenServer
① install served: the tab's navigation gets the server's shell, which loads /__hud/client.js, the page's own data-hud script dropped; static: build/hud.js the shell's <hud-link server shell>, or the page's <hud-link server> in the framed page, injected if it has none the release
② find querySelector('hud-link'), served = hasAttribute('server'), a frame for the tab's URL when it has shell the DOM host, served, frame start_link args
③ mount mount({ frame, host, served }): throws with no host host a div with an open shadow root and its stylesheet init
④ revive createLayer: the layer machine from its saved snapshot sessionStorage hud:layer the layer actor, not started init: state
⑤ start actor.start(), restore, then link.server or link.static the snapshot, served menus closed, a popped-out rail parked; saved again and hud:state emitted on every move init: state
⑥ attach attach: render, listen, observe, and settleAfter's 1500 ms timer, then ready; under a shell again on each load of the frame, the last page's listeners stopped the page: the tab's document, or the frame's pins on the page, hud:threads, hud:state and hud:view on its <hud-link>; at 1500 ms, threads whose element is gone may re-anchor init returns; a timeout: handle_info(settled)
⑦ recall link(hud, host, frame): the browser's own threads localStorage hud:local the local list, held aside —
⑧ link follow: server opens /__hud/ws and says hello { page }; local or static shows the kept list the layer's link a socket, retried each second while it drops call(server, hello)
⑨ ready the server's threads frame is drawn the frame pins and the rail; hud:threads emitted the reply; later frames handle_info
⑩ first thread the owner's open: the server's born() creates the thread machine the open frame one thread machine in the store DynamicSupervisor start_child

The host is <hud-link>, a valid custom element name hud does not define yet; once the installed script defines it, ② and ③ fold into its connectedCallback and server becomes an attribute it observes.

Layer

The tab's own machine, revived at ④ and started at ⑤: seven regions side by side, each in one state at a time.

As built, from the machine itself: the structure on the left, the states on the right. ▾ opens or closes a state in both; ↳ before a name marks where a region starts, · a move that stays put.

Outer layer

The server owns each thread: one thread machine per thread, kept in its store. Every tab mirrors it through the threads frame, and feeds it with its drafts, sent over the tab's socket, while the agent feeds it over HTTP and hears back on a watch line. In local mode, and on a static page, the tab runs the thread machine itself and nothing crosses to the server.

As built: three places, with the thread machine drawn where it runs, on the server when linked and in the tab when local or static. Hover or focus a machine or an arrow to light what it touches.