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/// Runs `f()` immediately and returns its `Dispose`.
13/// NOTE: This does *not* currently tie the cleanup into `Scope`.
14/// If you want cleanup on unmount, use `scoped_effect` or `disposable_effect`.
15pub fn effect<F>(f: F) -> Dispose
16where
17 F: FnOnce() -> Dispose + 'static,
18{
19 f()
20}
21
22/// Helper to register cleanup inside effect.
23pub fn on_unmount(f: impl FnOnce() + 'static) -> Dispose {
24 Dispose::new(f)
25}