pub trait SignalSet<T> {
// Required methods
fn set(&self, new_value: T);
fn try_set(&self, new_value: T) -> Option<T>;
}
Expand description
This trait allows setting the value of a signal.
Required Methods§
Implementors§
impl<T> SignalSet<T> for RwSignal<T>
Examples
let count = create_rw_signal(cx, 0);
assert_eq!(count(), 0);
count.set(1);
assert_eq!(count(), 1);
impl<T> SignalSet<T> for SignalSetter<T>
impl<T> SignalSet<T> for WriteSignal<T>
Examples
let (count, set_count) = create_signal(cx, 0);
// notifies subscribers
set_count.update(|n| *n = 1); // it's easier just to call set_count(1), though!
assert_eq!(count(), 1);
// you can include arbitrary logic in this update function
// also notifies subscribers, even though the value hasn't changed
set_count.update(|n| if *n > 3 { *n += 1 });
assert_eq!(count(), 1);