pub trait SignalSet {
type Value;
// Required methods
fn set(&self, new_value: Self::Value);
fn try_set(&self, new_value: Self::Value) -> Option<Self::Value>;
}
Expand description
This trait allows setting the value of a signal.
Required Associated Types§
Required Methods§
Implementors§
source§impl<T> SignalSet for RwSignal<T>
impl<T> SignalSet for RwSignal<T>
§Examples
let count = create_rw_signal(0);
assert_eq!(count.get(), 0);
count.set(1);
assert_eq!(count.get(), 1);
source§impl<T> SignalSet for WriteSignal<T>
impl<T> SignalSet for WriteSignal<T>
§Examples
let (count, set_count) = create_signal(0);
// notifies subscribers
set_count.update(|n| *n = 1); // it's easier just to call set_count.set(1), though!
assert_eq!(count.get(), 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.get(), 1);