mod by_rc;
mod computed;
mod context;
mod drop_resource;
mod graph;
#[doc = include_str!("invariants.md")]
pub mod invariants {}
mod to_computed;
mod value;
pub use by_rc::ByRc;
pub use computed::Computed;
pub use context::Context;
pub use drop_resource::DropResource;
pub use graph::{Graph, GraphId};
pub use to_computed::ToComputed;
pub use value::Value;
pub trait Reactive<T>: PartialEq {
fn set(&self, value: T);
fn get(&self, context: &Context) -> T;
fn change(&self, change_fn: impl FnOnce(&mut T));
}
impl<T> Reactive<T> for Value<T>
where
T: Clone + PartialEq + 'static,
{
fn set(&self, value: T) {
Value::set(self, value)
}
fn get(&self, context: &Context) -> T {
Value::get(self, context)
}
fn change(&self, change_fn: impl FnOnce(&mut T)) {
Value::change(self, change_fn)
}
}
thread_local! {
static DEFAULT_GRAPH: Graph = Graph::new();
}
pub(crate) fn default_graph() -> Graph {
DEFAULT_GRAPH.with(Graph::clone)
}
pub fn transaction<R>(f: impl FnOnce(&Context) -> R) -> R {
default_graph().transaction(f)
}
pub fn on_after_transaction(callback: impl Fn() + 'static) -> DropResource {
default_graph().on_after_transaction(callback)
}
#[cfg(test)]
mod propagation_order;
#[cfg(test)]
mod tests;