ankurah_react_signals/
lib.rs

1pub mod effect;
2pub mod react_binding;
3
4// Re-export the ankurah-derive WasmSignal derive macro
5pub use ankurah_derive::WasmSignal;
6use reactive_graph::{effect::Effect, owner::LocalStorage, traits::Dispose};
7
8use wasm_bindgen::prelude::wasm_bindgen;
9
10#[wasm_bindgen]
11pub struct Subscription {
12    effect: Option<Effect<LocalStorage>>,
13}
14
15impl Subscription {
16    pub fn new(effect: Effect<LocalStorage>) -> Self { Self { effect: Some(effect) } }
17}
18
19// fn add_dependency<T>(signal: &reactive_graph::signal::ReadSignal<T>) {
20//     let foo = react_binding::CURRENT_STORE.with(|cell| cell.borrow());
21
22//     if let Some(store) = &*foo {
23//         signal.subscribe(store.notifier.clone());
24//     }
25// }
26
27#[wasm_bindgen]
28impl Subscription {
29    #[wasm_bindgen]
30    pub fn unsubscribe(&mut self) { self.effect.take().unwrap().dispose(); }
31}
32
33impl Drop for Subscription {
34    fn drop(&mut self) { self.effect.take().unwrap().dispose(); }
35}