Skip to main content

ravenrs_reactive/
lib.rs

1//! Reactive state for RavenRS.
2//!
3//! The model is deliberately single-threaded (`Rc`/`Cell`, no locks): UI state
4//! lives on the UI thread on every platform, including the browser main thread.
5//!
6//! * [`State<T>`] owns a value. Reading it inside [`Observer::track`] records a
7//!   dependency; writing it invalidates only the observers that read it.
8//! * [`Binding<T>`] is a read/write view of some state that a child component can
9//!   receive without knowing where the value lives (SwiftUI's `@Binding`).
10//! * [`Derived<T>`] is a cached computation over other states (a memo).
11//! * [`Observer`] is what the UI runtime uses to know when to rebuild.
12//!
13//! Dependencies are re-collected on every tracked run. Instead of keeping back
14//! references from observers to sources, each subscription carries the observer's
15//! run *epoch*; a subscription from an older run is ignored and pruned on the next
16//! notification. This keeps ownership one-directional (sources hold `Weak`
17//! observers) and makes dropping either side safe at any time.
18
19mod binding;
20mod derived;
21mod observer;
22mod state;
23
24pub use binding::Binding;
25pub use derived::Derived;
26pub use observer::Observer;
27pub use state::State;