Skip to content

struct

Signal

pub struct Signal<T: 'static> {
    /* private fields */
}

A reactive, shared, mutable value. Cloning a signal yields another handle to the same value.

Methods

new

pub fn new(value: T) -> Self

Create a new signal holding value.

with

pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R

Read the value by reference, subscribing the current effect.

with_untracked

pub fn with_untracked<R>(&self, f: impl FnOnce(&T) -> R) -> R

Read the value by reference without subscribing.

set

pub fn set(&self, value: T)

Replace the value and notify subscribers.

update

pub fn update(&self, f: impl FnOnce(&mut T))

Mutate the value in place and notify subscribers.

subscriber_count

pub fn subscriber_count(&self) -> usize

Number of live effects currently subscribed to this signal.

ptr_eq

pub fn ptr_eq(&self, other: &Self) -> bool

Whether two handles point at the same signal.

get

pub fn get(&self) -> T

Clone the value out, subscribing the current effect.

get_untracked

pub fn get_untracked(&self) -> T

Clone the value out without subscribing.

set_if_changed

pub fn set_if_changed(&self, value: T) -> bool

Set the value only if it differs; returns whether it changed.

Trait implementations