pub struct Signal<T> { /* private fields */ }Expand description
A value you set. A memo or effect that reads it reruns after it changes.
Create one with Owner::signal. The handle is a
small Copy key, so closures capture it by value. The value itself lives
in this thread’s runtime until the signal’s owner is disposed.
Implementations§
Source§impl<T: 'static> Signal<T>
impl<T: 'static> Signal<T>
Sourcepub fn read_only(&self) -> ReadSignal<T>
pub fn read_only(&self) -> ReadSignal<T>
A read-only view of this signal, for code that should only read it.
Sourcepub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn with<R>(&self, f: impl FnOnce(&T) -> R) -> R
Calls f with a reference to the value, without cloning it. Inside a
memo or effect, this makes it depend on the signal.
§Panics
If the signal’s owner was disposed, or if f writes this signal.
Sourcepub fn get_untracked(&self) -> Twhere
T: Clone,
pub fn get_untracked(&self) -> Twhere
T: Clone,
Like get, but records no dependency.
Sourcepub fn with_untracked<R>(&self, f: impl FnOnce(&T) -> R) -> R
pub fn with_untracked<R>(&self, f: impl FnOnce(&T) -> R) -> R
Like with, but records no dependency.
Sourcepub fn try_get(&self) -> Option<T>where
T: Clone,
pub fn try_get(&self) -> Option<T>where
T: Clone,
Like get, but returns None if the owner was disposed.
Sourcepub fn try_with<R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>
pub fn try_with<R>(&self, f: impl FnOnce(&T) -> R) -> Option<R>
Like with, but returns None if the owner was
disposed.
Sourcepub fn set(&self, value: T)
pub fn set(&self, value: T)
Stores a new value, marks every memo and effect that read this signal
as stale, and queues the effects. Nothing runs until the next
Runtime::flush. Dependents are notified
even when the new value equals the old one.
§Panics
If the signal’s owner was disposed, if this runs inside a memo (use an
effect to write signals), or if it runs inside a with
call on the same signal.
Sourcepub fn try_set(&self, value: T) -> bool
pub fn try_set(&self, value: T) -> bool
Like set, but if the owner was disposed it does
nothing and returns false.