repose_core/effects.rs
1pub struct Dispose(Box<dyn FnOnce()>);
2
3impl Dispose {
4 pub fn new(f: impl FnOnce() + 'static) -> Self {
5 Dispose(Box::new(f))
6 }
7 pub fn run(self) {
8 (self.0)()
9 }
10}
11
12/// Mimic Compose side-effect. You call effect(|| { ...; on_unmount(...) })
13pub fn effect<F>(f: F) -> Dispose
14where
15 F: FnOnce() -> Dispose + 'static,
16{
17 f()
18}
19
20/// Helper to register cleanup inside effect.
21pub fn on_unmount(f: impl FnOnce() + 'static) -> Dispose {
22 Dispose::new(f)
23}