use crate::context::Context;
pub fn on_mount<F, Cleanup>(ctx: &mut Context, f: F)
where
F: FnOnce() -> Cleanup + Send + 'static,
Cleanup: FnOnce() + Send + 'static,
{
let already_mounted = ctx.state(false);
if !already_mounted.get() {
already_mounted.set(true);
let cleanup = f();
ctx.on_cleanup(cleanup);
}
}
pub fn on_unmount(ctx: &mut Context, f: impl FnOnce() + Send + 'static) {
let already_registered = ctx.state(false);
if !already_registered.get() {
already_registered.set(true);
ctx.on_cleanup(f);
}
}