pub trait SignalGet<T> {
    // Required methods
    fn get(&self) -> T;
    fn try_get(&self) -> Option<T>;
}
Expand description

This trait allows getting an owned value of the signals inner type.

Required Methods§

source

fn get(&self) -> T

Clones and returns the current value of the signal, and subscribes the running effect to this signal.

Panics

Panics if you try to access a signal that was created in a Scope that has been disposed.

source

fn try_get(&self) -> Option<T>

Clones and returns the signal value, returning Some if the signal is still alive, and None otherwise.

Implementors§

source§

impl<T: Clone> SignalGet<T> for MaybeSignal<T>

Examples

let (count, set_count) = create_signal(cx, 2);
let double_count = MaybeSignal::derive(cx, move || count() * 2);
let memoized_double_count = create_memo(cx, move |_| count() * 2);
let static_value: MaybeSignal<i32> = 5.into();

// this function takes any kind of wrapped signal
fn above_3(arg: &MaybeSignal<i32>) -> bool {
    arg.get() > 3
}

assert_eq!(above_3(&count.into()), false);
assert_eq!(above_3(&double_count), true);
assert_eq!(above_3(&memoized_double_count.into()), true);
assert_eq!(above_3(&static_value.into()), true);
source§

impl<T: Clone> SignalGet<T> for Memo<T>

Examples

let (count, set_count) = create_signal(cx, 0);
let double_count = create_memo(cx, move |_| count() * 2);

assert_eq!(double_count.get(), 0);
set_count(1);

// double_count() is shorthand for double_count.get()
assert_eq!(double_count(), 2);
source§

impl<T: Clone> SignalGet<T> for Signal<T>

Examples

let (count, set_count) = create_signal(cx, 2);
let double_count = Signal::derive(cx, move || count() * 2);
let memoized_double_count = create_memo(cx, move |_| count() * 2);

// this function takes any kind of wrapped signal
fn above_3(arg: &Signal<i32>) -> bool {
    arg.get() > 3
}

assert_eq!(above_3(&count.into()), false);
assert_eq!(above_3(&double_count), true);
assert_eq!(above_3(&memoized_double_count.into()), true);
source§

impl<T: Clone> SignalGet<T> for ReadSignal<T>

Examples

let (count, set_count) = create_signal(cx, 0);

assert_eq!(count.get(), 0);

// count() is shorthand for count.get()
assert_eq!(count(), 0);
source§

impl<T: Clone> SignalGet<T> for RwSignal<T>

Examples

let count = create_rw_signal(cx, 0);

assert_eq!(count.get(), 0);

// count() is shorthand for count.get()
assert_eq!(count(), 0);