A Derived signal wraps an existing Signal and computes its value lazily from the source signal on every read. It mirrors “computed” primitives from fine-grained reactive frameworks but works uniformly across all adapters: on Leptos, Dioxus, and Floem the source read inside the closure is tracked by the reactive graph; on GPUI and Xilem a source mutation triggers a re-render and the next read recomputes.
Import: use quoin_core::prelude::*;
Functions
Section titled “Functions”| Item | Signature | Description |
|---|---|---|
derived |
pub fn derived<S, T, U, F>(source: &S, f: F) -> Derived<S, T, U, F> where F: Fn(&T) -> U + Clone + 'static |
Creates a read-only signal computing U from the source’s T. The closure runs on every read — keep it cheap. |
zip |
pub fn zip<A, B, TA, TB>(a: &A, b: &B) -> Zipped<A, B, TA, TB> |
Combines two signals into a read-only signal of their tuple, recomputed on each read. |
memo |
pub fn memo<S, T, U, F>(source: &S, f: F) -> Memo<S, T, U, F> |
A derived signal that caches its last output until the source value changes. |
| Type | Description |
|---|---|
Derived<S, T, U, F> |
Read-only computed signal. Implements Signal<U>; reading clones the computed value. |
Zipped<A, B, TA, TB> |
Read-only signal combining two sources into a tuple. Created by zip. |
Memo<S, T, U, F> |
Caching derived signal: plain derived recomputes the closure on every read, Memo recomputes only when the source value differs from the last seen value. |
SignalExt sugar
Section titled “SignalExt sugar”| Method | Description |
|---|---|
.map(f) |
Equivalent to derived(self, f) — chainable for multi-step computations. |
Example
Section titled “Example”let count = cx.create_signal(2u32);
let label = count.map(|n| format!("count = {n}")); // recomputed on readassert_eq!(label.get(), "count = 2");
let doubled = quoin_core::derived(&count, |v| v * 2);assert_eq!(doubled.get(), 4);
let both = quoin_core::zip(&a, &b); // tuple of two signalsassert_eq!(both.get(), (1, 2));
let expensive = quoin_core::memo(&source, heavy_transform);Next steps
Section titled “Next steps”-
Writing Portable HooksWhere derived signals fit in portable hook design.
-
The Reactivity ModelHow pull-based and fine-grained adapters both support derived state.
