Runtime

signal

Create a reactive value in the current scope and read or write it through the runtime.

FNcx.signal
Counter
let count = cx.signal(0);
 
button("+1").on_click(move |cx, _| {
    count.update(cx, |count| *count += 1)
})
Signature
pub fn signal<T: 'static>(&mut self, value: T) -> Signal<T>

signal stores value in the current scope and returns a Signal<T> handle. The handle is Copy, so closures can capture it by value. The value is dropped when its scope is disposed.

Parameters

valueT: 'staticrequired

The initial value.

Signal methods

getfn(self, &mut Runtime) -> T

Clones the value and subscribes the running observer. Panics when the signal's scope was disposed.

try_getfn(self, &mut Runtime) -> Option<T>

Clones the value, or returns None when the signal was disposed.

withfn(self, &mut Runtime, impl FnOnce(&T) -> R) -> R

Lends the value to a closure and subscribes the running observer.

with_untrackedfn(self, &Runtime, impl FnOnce(&T) -> R) -> R

Lends the value without subscribing anything.

setfn(self, &mut Runtime, T)

Replaces the value and marks subscribers dirty.

updatefn(self, &mut Runtime, impl FnOnce(&mut T))

Mutates the value in place and marks subscribers dirty.