reactive_graph/README.md
An implementation of a fine-grained reactive system.
Fine-grained reactivity is an approach to modeling the flow of data through an interactive application by composing together three categories of reactive primitives:
Signals and computations are "source" nodes in the reactive graph, because an observer can subscribe to them to respond to changes in their values. Effects and computations are "subscriber" nodes, because they can listen to changes in other values.
use reactive_graph::{
computed::ArcMemo,
effect::Effect,
prelude::{Read, Set},
signal::ArcRwSignal,
};
let count = ArcRwSignal::new(1);
let double_count = ArcMemo::new({
let count = count.clone();
move |_| *count.read() * 2
});
// the effect will run once initially
Effect::new(move |_| {
println!("double_count = {}", *double_count.read());
});
// updating `count` will propagate changes to the dependencies,
// causing the effect to run again
count.set(2);
This reactivity is called "fine grained" because updating the value of a signal only affects the effects and computations that depend on its value, without requiring any diffing or update calculations for other values.
This model is especially suitable for building user interfaces, i.e., long-lived systems in which changes can begin from many different entry points. It is not particularly useful in "run-once" programs like a CLI.
wasm-bindgen-futures, in a native binary with tokio, in a GTK application with glib,
etc.)The reactive-graph algorithm used in this crate is based on that of Reactively, as described in this article.