Skip to main content

SignalWatch

Trait SignalWatch 

Source
pub trait SignalWatch {
    type Value;

    // Required method
    fn watch(&self, f: impl Fn(&Self::Value) + 'static) -> Box<dyn FnOnce()>;
}

Required Associated Types§

Required Methods§

Source

fn watch(&self, f: impl Fn(&Self::Value) + 'static) -> Box<dyn FnOnce()>

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>
where T: 'static, S: Storage<ArcRwSignal<T>> + Storage<ArcReadSignal<T>>,

Source§

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
Source§

type Value = T

Implementors§