Struct sycamore_reactive::ReadSignal
source · [−]pub struct ReadSignal<T> { /* private fields */ }
Expand description
A read-only Signal
.
Implementations
sourceimpl<T> ReadSignal<T>
impl<T> ReadSignal<T>
sourcepub fn get(&self) -> Rc<T>
pub fn get(&self) -> Rc<T>
Get the current value of the state. When called inside a reactive scope, calling this will add itself to the scope’s dependencies.
Example
let state = ctx.create_signal(0);
assert_eq!(*state.get(), 0);
state.set(1);
assert_eq!(*state.get(), 1);
sourcepub fn get_untracked(&self) -> Rc<T>
pub fn get_untracked(&self) -> Rc<T>
Get the current value of the state, without tracking this as a dependency if inside a reactive context.
Example
let state = ctx.create_signal(1);
let double = ctx.create_memo(|| *state.get_untracked() * 2);
assert_eq!(*double.get(), 2);
state.set(2);
// double value should still be old value because state was untracked
assert_eq!(*double.get(), 2);
sourcepub fn map<'a, U>(
&'a self,
ctx: ScopeRef<'a>,
f: impl FnMut(&T) -> U + 'a
) -> &'a ReadSignal<U>
pub fn map<'a, U>(
&'a self,
ctx: ScopeRef<'a>,
f: impl FnMut(&T) -> U + 'a
) -> &'a ReadSignal<U>
Creates a mapped ReadSignal
. This is equivalent to using
create_memo
.
Example
let state = ctx.create_signal(1);
let double = state.map(&ctx, |&x| x * 2);
assert_eq!(*double.get(), 2);
state.set(2);
assert_eq!(*double.get(), 4);
sourcepub fn track(&self)
pub fn track(&self)
When called inside a reactive scope, calling this will add itself to the scope’s dependencies.
To both track and get the value of the signal, use ReadSignal::get
instead.
Trait Implementations
sourceimpl<'a, T> AnyReadSignal<'a> for ReadSignal<T>
impl<'a, T> AnyReadSignal<'a> for ReadSignal<T>
sourcefn track(&self)
fn track(&self)
Call the ReadSignal::track
method.
sourceimpl<T: Debug> Debug for ReadSignal<T>
impl<T: Debug> Debug for ReadSignal<T>
sourceimpl<T: Display> Display for ReadSignal<T>
impl<T: Display> Display for ReadSignal<T>
sourceimpl<T: Hash> Hash for ReadSignal<T>
impl<T: Hash> Hash for ReadSignal<T>
sourceimpl<T: PartialEq> PartialEq<ReadSignal<T>> for ReadSignal<T>
impl<T: PartialEq> PartialEq<ReadSignal<T>> for ReadSignal<T>
impl<T: Eq> Eq for ReadSignal<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for ReadSignal<T>
impl<T> !Send for ReadSignal<T>
impl<T> !Sync for ReadSignal<T>
impl<T> Unpin for ReadSignal<T>
impl<T> !UnwindSafe for ReadSignal<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Q where
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcepub fn equivalent(&self, key: &K) -> bool
pub fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.