Attribute Graph and Reactivity
Track typed values and dynamic dependencies while keeping propagation separate from view scheduling.
Kit's attribute graph records values and the computations that depend on them. The runtime assigns each value an opaque process-local AttrId and stores its revision together with dependency indexes. IDs are unique across graphs, allowing handles to identify runtime storage without treating them as persistent application IDs or wire node IDs.
Derived Computations
A writable value is accessed through State<T>, while Derived<T> supplies a computation whose output depends on other attributes. As that computation reads through Eval::get, the runtime records edges from the values it read to its output. Those edges tell propagation which computations may need to run after a write.
The dependency set follows the computation's actual reads. On reevaluation, the new reads replace the old ones, allowing a conditional computation to observe a different set of attributes. Use Eval::get_untracked when a read should deliberately leave that dependency set unchanged.
Write Propagation
A normal state write replaces the value and advances its revision, queues dependents, and drains propagation unless a batch is open. Derived recomputation updates its dependency set and queues downstream work.
Propagation processes a worklist whose currently queued entries are deduplicated. This avoids redundant pending work without promising that a derived attribute can run only once during an update. A computation may be revisited as dependencies change, and a visit limit detects likely cycles that would otherwise keep the worklist active.
Normal writes and recomputations advance revisions even when the resulting value compares equal. set_if_changed suppresses an equal state write for values supporting PartialEq.
Propagation Batches
Batching delays automatic derived propagation until the outermost begin_batch/end_batch scope closes. The underlying state writes happen immediately, so reads of state inside the batch see the new values even while derived outputs may still reflect earlier inputs. Code reading a derived value must account for that propagation boundary.
Runtime::mutate keeps the batch bookkeeping scoped to its callback. If the callback panics, the runtime restores that bookkeeping and resumes the panic, while any completed writes remain in place. Batching therefore groups propagation work without supplying transactional rollback for model values or retained scenes.
View Scheduling
Graph propagation does not independently wake AppHost. The UI loop schedules evaluation after input, external updates, surface changes, and explicit render requests.
Memoization records a different kind of dependency from the graph's derived edges. Eval::get connects computations for propagation, whereas runtime reads during memo evaluation record attribute IDs and revisions for later subtree reuse. A normal cx.read therefore does not install a separately scheduled computation for the body that performed it.
Dependency Edge Retirement
When the final owner of a mounted attribute lease drops, the runtime queues the attribute for retirement. Collection removes its value and incident edges, including computed-reader relationships. Reverse indexes let that cleanup follow the affected edges instead of scanning the whole graph for every retired value.
Application code should use state and binding methods rather than mutating raw graph storage, which bypasses propagation and scheduling responsibilities.
Source Reference
The following files in the Hera checkout define the behavior described on this page.
crates/kit/src/ag/mod.rscrates/kit/src/ag/binding.rscrates/kit/src/ag/reactive.rs