pub trait SignalWatch {
type Value;
// Required method
fn watch(&self, f: impl Fn(&Self::Value) + 'static) -> Box<dyn FnOnce()>;
}Required Associated Types§
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T, S> SignalWatch for RwSignal<T, S>
impl<T, S> SignalWatch for RwSignal<T, S>
Source§fn watch(
&self,
f: impl Fn(&<RwSignal<T, S> as SignalWatch>::Value) + 'static,
) -> Box<dyn FnOnce()>
fn watch( &self, f: impl Fn(&<RwSignal<T, S> as SignalWatch>::Value) + 'static, ) -> Box<dyn FnOnce()>
§Usage
use leptos::prelude::*;
use thaw_utils::SignalWatch;
let count = RwSignal::new(0);
let stop = count.watch(|count| {
assert_eq!(count, &1);
});
count.set(1); // assert_eq!(count, &1);
stop(); // stop watching
count.set(2); // nothing happens