observe/
lib.rs

1pub mod macros;
2
3mod addr;
4mod batch;
5mod computed;
6mod r#const;
7mod dependencies;
8mod evaluation;
9mod hashed;
10mod reaction;
11mod value;
12mod var;
13
14#[cfg(target_arch = "wasm32")]
15mod microtask;
16
17use std::rc::{Rc, Weak};
18
19pub use batch::{batch, batch_microtask, in_batch};
20pub use computed::Computed;
21pub use dependencies::Dependencies;
22pub use evaluation::Evaluation;
23pub use hashed::Hashed;
24pub use reaction::{Reaction, Reactions, Reactive, CHANGED};
25pub use value::Value;
26pub use var::Var;
27
28pub trait Derived: 'static {
29	fn invalidate(self: Rc<Self>, invalid: Invalid);
30}
31
32pub trait Observable: 'static {
33	/// This function is called when we want
34	/// this observable to recompute itself.
35	fn update(&self) -> Version;
36
37	/// This function should return the current
38	/// computed version.
39	fn version(&self) -> Version;
40
41	/// Notify this observable that `derived` started
42	/// to listen.
43	fn used_by(&self, derived: Weak<dyn Derived>);
44
45	/// Notify this observable that `derived` stopped
46	/// to listen.
47	fn not_used_by(&self, derived: &Weak<dyn Derived>);
48}
49
50#[derive(PartialEq, Eq, Clone, Copy)]
51pub enum State {
52	Valid,
53	Invalid(Invalid),
54}
55
56#[derive(PartialEq, Eq, Clone, Copy)]
57pub enum Invalid {
58	Maybe,
59	Definitely,
60}
61
62#[derive(PartialEq, Eq)]
63pub enum Version {
64	Hash(u64),
65}