Struct sycamore_reactive::Signal [−][src]
pub struct Signal<T: 'static> { /* fields omitted */ }
Expand description
State that can be set.
Example
use sycamore_reactive::*;
let state = Signal::new(0);
assert_eq!(*state.get(), 0);
state.set(1);
assert_eq!(*state.get(), 1);
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 = Signal::new(0);
assert_eq!(*state.get(), 0);
state.set(1);
assert_eq!(*state.get(), 1);
Get the ReadSignal
associated with this signal.
This is a shortcut for (*signal).clone()
.
Consumes this signal and returns its underlying ReadSignal
.
Calls all the subscribers without modifying the state.
This can be useful when using patterns such as inner mutability where the state updated will
not be automatically triggered. In the general case, however, it is preferable to use
Signal::set
instead.
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
use sycamore_reactive::*;
let state = Signal::new(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
use sycamore_reactive::*;
let state = Signal::new(1);
let double = create_memo({
let state = state.clone();
move || *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);
Trait Implementations
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.