use std::marker::PhantomData;
use crate::handle::{NotSend, handle_impls};
use crate::runtime::{self, Computed, NodeId};
pub struct Effect {
id: NodeId,
_not_send: NotSend,
}
handle_impls!(Effect);
impl Effect {
#[track_caller]
pub(crate) fn new(owner: NodeId, mut f: impl FnMut() + 'static) -> Self {
let compute = move || {
f();
Computed {
changed: true,
leftover: None,
}
};
Effect {
id: runtime::create_effect(owner, Box::new(compute)),
_not_send: PhantomData,
}
}
pub fn named(self, name: impl Into<String>) -> Self {
runtime::set_name(self.id, name.into());
self
}
}