crate
weft_reactive
Weft reactive primitives.
A small, single-threaded, fine-grained reactive system (WASM in the browser is single-threaded, so Rc/RefCell is all we need):
Signal— a mutable value that records who reads it.Effect— a side effect that re-runs whenever a signal it read changes.Memo— a cached derived value that only notifies when it changes.batch/untrack— control when effects run and what is tracked.Owner— keeps effects alive and disposes them together (used for component lifetimes).
Structs
- Effect
A side effect that tracks the signals it reads and re-runs when they change. The effect lives as long as a handle (or an
Owner) holds it. - Memo
A cached derived value. Readers are only notified when the computed value actually changes (by
PartialEq). - Owner
Owns the effects created inside [
Owner::run], keeping them alive until [Owner::dispose]. Components use an owner to tie effects to their lifetime. - Signal
A reactive, shared, mutable value. Cloning a signal yields another handle to the same value.
Functions
batch
pub fn batch<R>(f: impl FnOnce() -> R) -> RRun f, deferring effect execution until it returns. Each affected effect runs at most once per (outermost) batch.
is_tracking
pub fn is_tracking() -> boolWhether code is currently running inside an effect that tracks reads.
on_cleanup
pub fn on_cleanup(f: impl FnOnce() + 'static)Run f when the current Owner is disposed (for a component: when it stops being rendered). Without an owner, f never runs.