std1.0.0-beta-7 SafeC docs

Module wasm::hydrate

#include <std/wasm/hydrate.h> source

WASM client hydration.

The piece that actually ties std/reactive/signal.h's Signal<T> to std/wasm/dom.h's DOM bindings: fine-grained, SolidJS-style hydration — a Signal knows exactly which DOM node(s) depend on it (via subscribe()) and pushes updates directly, no virtual DOM / diff / re-render-the-tree step. A hydrated page is server-rendered scx markup (see std/scx/scx.h) whose interactive elements the client-side wasm module locates by selector and wires up on startup — see examples/fullstack_demo for the full round trip (server render + server function + hydrated client interactivity).

Structs

HydrateFmtBindingText content from any Signal<T>, rendered by 'format' (which appends the text for a value to 'out').

Functions

hydrate_bind_text_int_handleBinds 'signal' (must hold an 'int') so every future change formats its value as decimal text and writes it into 'elementHandle's text content. Does not set the element's initial text — call dom_set_text() yourself first (or set() once) if it needs to show a value before the first change.
hydrate_bind_text_intConvenience: dom_get_element(selector) + hydrate_bind_text_int_handle(). Returns the resolved element handle (-1 if 'selector' matched nothing, in which case no binding was registered).
hydrate_bind_textText content from a Signal<String>.
hydrate_bind_attrAn attribute's value from a Signal<String>.
hydrate_bind_classAdds 'cls' to the element's classList while the signal is non-zero, removes it otherwise.
hydrate_bind_visibleShows the element while the signal is non-zero (style.display), hides it otherwise.
hydrate_bind_valueTwo-way binding for an <input>/<textarea>/<select>: the control's value follows the signal, and every "input" event stores the control's value into the signal (which notifies the signal's other subscribers). Returns the listener id (dom_off() stops the DOM -> signal half).
hydrate_bind_checkedTwo-way binding of a checkbox's .checked to a Signal<int> ("change").
hydrate_bind_text_with