Struct sycamore_reactive::Signal
source · [−]pub struct Signal<T>(_);
Expand description
Reactive state that can be updated and subscribed to.
Implementations
Set the current value of the state.
This will notify and update any effects and memos that depend on this value.
Example
let state = ctx.create_signal(0);
assert_eq!(*state.get(), 0);
state.set(1);
assert_eq!(*state.get(), 1);
Set the current value of the state without triggering subscribers.
Make sure you know what you are doing because this can make state inconsistent.
Take the current value out and replace it with the default value.
This will notify and update any effects and memos that depend on this value.
Take the current value out and replace it with the default value without triggering subscribers.
Make sure you know what you are doing because this can make state inconsistent.
Methods from Deref<Target = ReadSignal<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);
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);
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);
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
Call the ReadSignal::track
method.
type Target = ReadSignal<T>
type Target = ReadSignal<T>
The resulting type after dereferencing.
Auto Trait Implementations
impl<T> !RefUnwindSafe for Signal<T>
impl<T> !UnwindSafe for Signal<T>
Blanket Implementations
Mutably borrows from an owned value. Read more
Compare self to key
and return true
if they are equal.