NAME
bud/bud_reconcile.h - Host-agnostic reactive VDOM reconciler, hooks, and component runtime.
SYNOPSIS
#include 'bud.h'
#include <stddef.h>
#include <stdint.h>
Data Structures
Host realization vtable (DOM, liblamina, or custom renderer).
Macros
Typed state hook macro: int *count = bud_use_state(int, 0);.
Typed state setter macro: bud_set(count, *count + 1);.
Typed ref hook macro: int *r = bud_use_ref(int, 0);.
Convenience constructor for a keyed or unkeyed component VNode.
Typedefs
Opaque mounted reconciler instance.
Cleanup callback returned by a bud_effect_fn.
Post-commit effect callback; may return an optional cleanup callback.
Host realization vtable (DOM, liblamina, or custom renderer).
Functions
Create a new reconciler mount targeting root_host.
Reconcile root_vnode into the mount and run post-commit effects.
Re-render only dirty component subtrees (sorted parent-first) and run effects.
Non-zero when at least one mounted component cell is dirty.
Return the root host container handle passed to bud_mount_new.
Unmount all cells (invoking effect cleanups and destroying host nodes).
Unmount and free the bud_mount handle.
Allocate or retrieve stable state storage for the current component cell.
Update state value obtained from bud_use_state_raw and mark owner dirty.
Allocate or retrieve stable mutable ref storage (mutations do not re-render).
Schedule a post-commit effect with optional byte-compared dependency snapshot.
Variables
Sentinel deps pointer meaning run effect after every commit.
Detailed Description
Host-agnostic reactive VDOM reconciler, hooks, and component runtime.
Reconciles bud_node trees (including lazy BUD_NODE_COMPONENT nodes) into any concrete UI host implementing bud_host_ops (browser DOM via WASM, native desktop / WebGL via liblamina, or test mocks). Pure C, zero host deps.
Typedef Documentation
typedef struct bud_host_ops bud_host_ops
Host realization vtable (DOM, liblamina, or custom renderer). Ownership contract:
- insert_before inserts or moves child before before (or appends if NULL) without destroying child.
- remove_child detaches child from parent without freeing it.
- destroy_node frees a detached host node and any host-side metadata.
- clear_children (optional) destroys all children of parent in O(1) when no mounted subtree holds active effect cleanups.
Function Documentation
int bud_mount_flush (bud_mount * mount)
Re-render only dirty component subtrees (sorted parent-first) and run effects.
Parameters
mount Target mount.
Returns
Number of component cells re-rendered, or -1 on error.
bud_mount * bud_mount_new (const bud_host_ops * ops, void * host_ctx, void * root_host)
Create a new reconciler mount targeting root_host.
Parameters
ops Host vtable (copied internally; must remain valid functions).
host_ctx Opaque context forwarded to every host callback.
root_host Concrete root container handle in the host.
Returns
Mounted reconciler handle, or NULL on allocation failure.
int bud_mount_update (bud_mount * mount, const bud_node * root_vnode)
Reconcile root_vnode into the mount and run post-commit effects. Borrows root_vnode (caller retains ownership and may free or SSR-render it). Pass NULL to unmount all children from root_host.
Parameters
mount Target mount.
root_vnode Root virtual node tree (or NULL to clear).
Returns
0 on success, -1 on error.
int bud_set_state_raw (void * state_ptr, const void * next_val, size_t size)
Update state value obtained from bud_use_state_raw and mark owner dirty. Performs byte-level equality bailout: if the value is unchanged, the owning component cell is not marked dirty.
Parameters
state_ptr Stable pointer previously returned by bud_use_state_raw.
next_val Pointer to new value bytes.
size Byte size of value (must match state slot size).
Returns
1 if state changed and owner was dirtied, 0 if unchanged, -1 on error.
void bud_use_effect (bud_effect_fn fn, void * user, const void * deps, size_t deps_size)
Schedule a post-commit effect with optional byte-compared dependency snapshot.
Parameters
fn Effect callback invoked after commit; may return cleanup fn.
user User pointer passed to fn (and to its returned cleanup fn).
deps Pointer to dependency struct/value, NULL (once on mount), or BUD_DEPS_ALWAYS.
deps_size Byte size of deps (0 when deps is NULL).
void * bud_use_state_raw (size_t size, const void * init)
Allocate or retrieve stable state storage for the current component cell.
Parameters
size Byte size of the state value.
init Pointer to initial value bytes (or NULL for zero-init).
Returns
Stable pointer to the state payload (valid until component unmounts).
Author
Generated automatically by Doxygen for bud from the source code.