1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
pub mod macros;

mod addr;
mod batch;
mod computed;
mod r#const;
mod dependencies;
mod evaluation;
mod hashed;
mod reaction;
mod value;
mod var;

#[cfg(target_arch = "wasm32")]
mod microtask;

use std::rc::{Rc, Weak};

pub use batch::{batch, batch_microtask, in_batch};
pub use computed::Computed;
pub use dependencies::Dependencies;
pub use evaluation::Evaluation;
pub use hashed::Hashed;
pub use reaction::{Reaction, Reactions, Reactive, CHANGED};
pub use value::Value;
pub use var::Var;

pub trait Derived: 'static {
	fn invalidate(self: Rc<Self>, invalid: Invalid);
}

pub trait Observable: 'static {
	/// This function is called when we want
	/// this observable to recompute itself.
	fn update(&self) -> Version;

	/// This function should return the current
	/// computed version.
	fn version(&self) -> Version;

	/// Notify this observable that `derived` started
	/// to listen.
	fn used_by(&self, derived: Weak<dyn Derived>);

	/// Notify this observable that `derived` stopped
	/// to listen.
	fn not_used_by(&self, derived: &Weak<dyn Derived>);
}

#[derive(PartialEq, Eq, Clone, Copy)]
pub enum State {
	Valid,
	Invalid(Invalid),
}

#[derive(PartialEq, Eq, Clone, Copy)]
pub enum Invalid {
	Maybe,
	Definitely,
}

#[derive(PartialEq, Eq)]
pub enum Version {
	Hash(u64),
}