use super::*;
impl Effect {
pub fn new<F>(callback: F) -> Self
where
F: FnMut() + 'static,
{
let id: EffectId = with_runtime(
|rt: &mut ReactiveRuntime| rt.create_effect(callback),
EffectId::default(),
);
run_effect(id);
Self { id }
}
#[must_use]
pub fn id(&self) -> EffectId {
let Self { id } = *self;
id
}
pub fn dispose(&self) {
let id: EffectId = self.id();
with_runtime(
|rt: &mut ReactiveRuntime| {
rt.dispose_effect(id);
},
(),
);
}
}