bud/bud_reconcile.h(3)bud

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

struct bud_host_ops

Host realization vtable (DOM, liblamina, or custom renderer).

Macros

#define bud_use_state(T, init_val)

Typed state hook macro: int *count = bud_use_state(int, 0);.

#define bud_set(ptr, next_val)

Typed state setter macro: bud_set(count, *count + 1);.

#define bud_use_ref(T, init_val)

Typed ref hook macro: int *r = bud_use_ref(int, 0);.

#define bud_comp(fn, props_type, ...)

Convenience constructor for a keyed or unkeyed component VNode.

Typedefs

typedef struct bud_mount bud_mount

Opaque mounted reconciler instance.

typedef void(* bud_effect_cleanup_fn) (void *user)

Cleanup callback returned by a bud_effect_fn.

typedef bud_effect_cleanup_fn(* bud_effect_fn) (void *user)

Post-commit effect callback; may return an optional cleanup callback.

typedef struct bud_host_ops bud_host_ops

Host realization vtable (DOM, liblamina, or custom renderer).

Functions

bud_mount * bud_mount_new (const bud_host_ops *ops, void *host_ctx, void *root_host)

Create a new reconciler mount targeting root_host.

int bud_mount_update (bud_mount *mount, const bud_node *root_vnode)

Reconcile root_vnode into the mount and run post-commit effects.

int bud_mount_flush (bud_mount *mount)

Re-render only dirty component subtrees (sorted parent-first) and run effects.

int bud_mount_is_dirty (const bud_mount *mount)

Non-zero when at least one mounted component cell is dirty.

void * bud_mount_root_host (const bud_mount *mount)

Return the root host container handle passed to bud_mount_new.

void bud_mount_unmount (bud_mount *mount)

Unmount all cells (invoking effect cleanups and destroying host nodes).

void bud_mount_free (bud_mount *mount)

Unmount and free the bud_mount handle.

void * bud_use_state_raw (size_t size, const void *init)

Allocate or retrieve stable state storage for the current component cell.

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.

void * bud_use_ref_raw (size_t size, const void *init)

Allocate or retrieve stable mutable ref storage (mutations do not re-render).

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.

Variables

const char bud_deps_always_sentinel

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:

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.