Trait leptos_reactive::SignalGet
source · 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§
Implementors§
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);
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);
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);
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);
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);