Skip to main content

Module swap

Module swap 

Source
Expand description

UI-6: the module registry, hot-swap and the sections.

The registry is the live version’s manifest.json: each component’s name → the hashes of its tree and handlers. A mounted component is an instance: its element (named for the component), its props, its state, its folds and the version it was drawn from.

  • Hot-swap (App::swap): a new manifest; each mounted instance whose tree or handlers hash changed is remounted into the same element with the same props — its state carried over when the declared state’s shape (its keys) is unchanged, else the new initial state; every other instance is untouched. One that fails to mount (a malformed tree, handlers refused) keeps its last good version drawn, and the console says so.
  • Sections: a layout’s slot node draws as a div carrying data-layout and data-slot, filled by its assignment — from ui.slots.list (App::set_assignments), else manifest.slots’ default — with the slot’s attributes as props. A component of another version is drawn from that version’s files (Files::put_version, fetched by the engine from /app/<hash>/components/<name>.json and .rhai). slot_changed (App::slot_changed) remounts that section alone, its props kept.

What the engine fetches is handed in as Files (content-addressed by sha256), so everything here is synchronous: the browser fetches first, then swaps.

FRAME-12: a component of any profile but rhx/1 is a module (crate::module) the page imports and hands in with App::provide_module; it is mounted, swapped and filled by the same rules, with these: a module whose hash changed is destroyed, then mounted from the new version into the same element with the same props — and when that mount throws, the last good version is mounted again and the element marked; a section whose assignment changes mounts the new component before the old one is taken out, and when the new one fails the old stays drawn, marked; a route to the component already drawn is an update(props). Every mounted instance is a member of the page’s Bus (App::bus); an rhx fold hears the topics its tree’s bus names and runs with the bus held.

FRAME-29: a bound mark — a [data-slot] mark that also carries data-component (and, optionally, data-version) — is a section bound early: its code chose what fills it. The walk fills it with that component (of that version, else the live one) with the mark’s other data-* as props, whatever the assignments and slots.json say; no assignment, slot_changed or default reaches it, and slots_set on it is refused bound (crate::bus::BusRefusal::Bound). Its props follow the mark as an unbound section’s do; a mark whose binding changes is a new section; a swap remounts it when its component’s hash changed, as any instance (a data-version pins it); it goes when its mark does.

Structs§

App
The engine: the registry, the instances, the sections — over a renderer, the wire (for call and live) and a clock.
Assignment
What fills a section: (layout, slot) → (component, version) — kept by the ui service (ui.slots.*), said on ui.watch as slot_changed.
ComponentEntry
One component of a manifest.
Files
What the engine has fetched: each version’s component by (version, name) — /app/<version>/components/<name>.json and .rhai.
Manifest
A bundle’s manifest.json.
Menu
The section menu (a right-click on a section): the live bundle’s components by name, and the section’s component’s other stored versions — those whose hash for it differs from the live one’s — newest first, the live one excluded.
MountId
A mounted instance.
SwapReport
What a swap did.

Enums§

SwapError
Why a mount or a load did not happen.

Constants§

HELD
The hold’s attribute, and the engine’s sheet that hides what carries it.
MARK_NAMES
FRAME-18: a mark’s slot (its data-slot) and its props (its other data-* attributes, data-layout aside, the data- taken off). FRAME-29: and its binding — data-component, with data-version when it names one — neither of them a prop. STUDIO-6: what a mark never hands its component as a prop — the section’s own names and the engine’s (data-failed and data-css on a component’s element, data-refused in its menu): one list, which CONTRACT.md’s “A bound mark” names. (An unbound mark’s data-version stays its prop, FRAME-18: a version binds only beside a component.)

Functions§

sha256_hex
The sha256 of text, hex — what a manifest names a file by.

Type Aliases§

Yield
What runs f in a task of its own, after the tasks already queued.