Expand description
Reactive Rust for HTML script blocks, compiled by Cargo without a Rust DSL.
use fusor::{signal, derived, effect, batch};
let count = signal(0);
let doubled = derived({ let count = count.clone(); move || count.get() * 2 });
let subscription = effect(move || println!("{}", doubled.get()));
batch(|| { count.set(2); count.set(3); });
// Prints 0, then 6. Dropping the subscription stops it.
drop(subscription);Re-exports§
pub use dom::FromInputs;pub use js::JsInputs;
Modules§
- coherence
- The renderer/readiness contract, independent of executors and the browser.
- dom
- Bind real DOM nodes to Rust closures. The browser creates the HTML DOM.
A
Scopeowns its effects and event listeners. Drop it to unmount behavior. - js
- Optional, component-local JavaScript modules and explicit Rust inputs.
- prelude
- The small set of types needed by a browser application.
Macros§
- bindings
- Include an HTML module’s generated bindings in the ordinary Rust module
declared by its script’s
rust:moduleattribute. The argument is the entry registration (app) or a component registration from Cargo metadata. - template
- Associate package-relative HTML with this ordinary Rust module.
Structs§
- Cleanup
- Run a callback exactly once when dropped. Combine with an owner registration or
effect_with_cleanupto release external resources. - Cleanup
Effect - A reactive execution with a guard released before the next execution and on disposal. Destructors run without dependency tracking or registry borrows.
- Derived
- A lazy computation. Reads track its underlying signals in the consuming effect.
It is deliberately not a cache: each
getevaluates the function once. - Effect
- Owns a subscription. Dropping it detaches every dependency.
- Memo
- A shared lazy cache of a pure computation over tracked signals and memos.
- Owner
- A unique lifetime owner. Commit starts registered work; drop disposes it. Handles are weak and cannot extend the lifetime. This is single-threaded.
- Owner
Handle - Weak access to an owner’s lifecycle. Safe to retain after disposal.
- Registration
- Removing this registration unregisters the callback without invoking it.
- Signal
- Shared, single-threaded reactive state. Cloning shares the same value.
Enums§
- Context
Error - A context provider cannot be replaced or registered after disposal.
Traits§
- Context
Key - A typed, namespaced key for a value supplied by a component or application. Distinct key types can provide the same value type without colliding.
Functions§
- batch
- Group synchronous writes into one notification per affected effect. Nested batches flush at the outer boundary. This is not a rollback transaction.
- derived
- effect
- effect_
with_ cleanup - Track reads during setup, retaining its returned Rust value until replacement.
Return a
Cleanupfor callback-based APIs or any existing RAII guard. Cleanup itself is untracked. A rerun that panics has already released its old guard; Rust’s ordinary unwind/abort behavior applies to the setup operation. - memo
- Create a cached derivation using
PartialEqto suppress unchanged results. - memo_
with_ eq - Create a cached derivation with an explicit equivalence relation.
Equal values retain the old cache.
|_, _| falsepublishes every recomputation. - signal
- Create reactive state; reads inside an effect automatically subscribe to it.
- untrack
- Evaluate a closure without collecting dependencies in the current effect.
Derive Macros§
- From
Inputs - Generate a component’s named input struct and
FromInputsimplementation. Each field must be#[input]or#[local(init = expression)]. Seefusor::FromInputsfor the application-facing documentation. - JsInputs
- Expose only marked
Signal<T>fields to this component’s JavaScript module.