use crate::context::GraphNode;
pub trait Teardown {
fn len(&self) -> usize;
fn is_empty(&self) -> bool {
self.len() == 0
}
fn disarm(self)
where
Self: Sized;
}
pub trait ReactiveGraph {
type Computed<T>: GraphNode + Copy;
type Source<T>: GraphNode + Copy;
type Effect: GraphNode + Copy;
type Scope<'a>: Teardown
where
Self: 'a;
fn dispose_slot<T: 'static>(&self, handle: &Self::Computed<T>);
fn dispose_cell<T: 'static>(&self, handle: &Self::Source<T>);
fn dispose_effect(&self, handle: &Self::Effect);
fn scope(&self) -> Self::Scope<'_>;
fn batch<R>(&self, run: impl FnOnce(&Self) -> R) -> R;
fn dependent_count(&self, node: &impl GraphNode) -> usize;
fn dependency_count(&self, node: &impl GraphNode) -> usize;
}
pub trait ThreadSafeReactiveGraph: ReactiveGraph + Send + Sync + 'static {}
impl<T: ReactiveGraph + Send + Sync + 'static> ThreadSafeReactiveGraph for T {}
pub trait SyncReactiveGraph: ReactiveGraph {
type Compute<'a>
where
Self: 'a;
fn cell<T>(&self, value: T) -> Self::Source<T>
where
T: PartialEq + Send + Sync + 'static;
fn get_cell<T>(&self, handle: &Self::Source<T>) -> T
where
T: Clone + Send + Sync + 'static;
fn set_cell<T>(&self, handle: &Self::Source<T>, value: T)
where
T: PartialEq + Send + Sync + 'static;
fn computed<T, F>(&self, compute: F) -> Self::Computed<T>
where
T: PartialEq + Send + Sync + 'static,
F: Fn(&Self::Compute<'_>) -> T + Send + Sync + 'static;
fn get<T>(&self, handle: &Self::Computed<T>) -> T
where
T: Clone + Send + Sync + 'static;
fn effect<F, C>(&self, run: F) -> Self::Effect
where
F: Fn(&Self::Compute<'_>) -> C + Send + Sync + 'static,
C: FnOnce() + Send + Sync + 'static;
}
pub trait AsyncReactiveGraph: ReactiveGraph {
fn cell<T>(&self, value: T) -> Self::Source<T>
where
T: PartialEq + Clone + Send + Sync + 'static;
fn get_cell<T>(&self, handle: &Self::Source<T>) -> T
where
T: Clone + Send + Sync + 'static;
fn set_cell<T>(&self, handle: &Self::Source<T>, value: T)
where
T: PartialEq + Clone + Send + Sync + 'static;
fn get<T>(&self, handle: &Self::Computed<T>) -> impl Future<Output = T> + Send
where
T: Clone + Send + Sync + 'static;
}