Trait leptos::SignalSet

source ·
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§

source

type Value

The value held by the signal.

Required Methods§

source

fn set(&self, new_value: Self::Value)

Sets the signal’s value and notifies subscribers.

Note: set() does not auto-memoize, i.e., it will notify subscribers even if the value has not actually changed.

source

fn try_set(&self, new_value: Self::Value) -> Option<Self::Value>

Sets the signal’s value and notifies subscribers. Returns None if the signal is still valid, [Some(T)] otherwise.

Note: set() does not auto-memoize, i.e., it will notify subscribers even if the value has not actually changed.

Implementors§

source§

impl SignalSet for Trigger

§

type Value = ()

source§

impl<S, T> SignalSet for Resource<S, T>

§

type Value = T

source§

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);
§

type Value = T

source§

impl<T> SignalSet for SignalSetter<T>

§

type Value = T

source§

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);
§

type Value = T