use super::*;
impl Effect {
pub fn new<CallbackFn>(callback: CallbackFn) -> Self
where
CallbackFn: FnMut() + 'static,
{
let id: EffectId = with_runtime(
|runtime_ref: &mut ReactiveRuntime| runtime_ref.create_effect(callback),
EffectId::default(),
);
run_effect(id);
Self { id }
}
#[must_use]
pub fn id(&self) -> EffectId {
let Self { id } = *self;
id
}
#[must_use]
pub fn dependency_count(&self) -> usize {
let id: EffectId = self.id();
with_runtime_ref(
|runtime_ref: &ReactiveRuntime| runtime_ref.effect_dependency_count(id),
0,
)
}
#[must_use]
pub fn dependency_edge_snapshot(&self) -> Vec<(u32, u32)> {
let id: EffectId = self.id();
with_runtime_ref(
|runtime_ref: &ReactiveRuntime| runtime_ref.effect_edge_snapshot(id),
Vec::new(),
)
}
pub fn dispose(&self) {
let id: EffectId = self.id();
with_runtime(
|runtime_ref: &mut ReactiveRuntime| {
runtime_ref.dispose_effect(id);
},
(),
);
}
}