pub struct XSignal<T>(/* private fields */);Expand description
A mutable value that callbacks can subscribe to.
- Derived signals
- ReactiveClosures re-compute and update HTML nodes when signals change
Implementations§
Source§impl<T> XSignal<T>
impl<T> XSignal<T>
Source§impl<T> XSignal<T>
impl<T> XSignal<T>
Sourcepub fn new(name: impl Into<XString>, value: T) -> Self
pub fn new(name: impl Into<XString>, value: T) -> Self
Create a new signal.
The name of the signal is used in console logs, does not have to be unique.
Sourcepub fn add_subscriber(&self, closure: impl Fn(T) + 'static) -> Consumerswhere
T: Clone + 'static,
pub fn add_subscriber(&self, closure: impl Fn(T) + 'static) -> Consumerswhere
T: Clone + 'static,
Registers a callback that will trigger when the signal is updated.
Sourcepub fn get_value_untracked(&self) -> Twhere
T: Clone,
pub fn get_value_untracked(&self) -> Twhere
T: Clone,
Gets the current value of the signal.
Reactive behavior should use XSignal::add_subscriber.
Source§impl<T: Debug + 'static> XSignal<T>
impl<T: Debug + 'static> XSignal<T>
Sourcepub fn set(&self, new_value: impl Into<T>)where
T: Eq,
pub fn set(&self, new_value: impl Into<T>)where
T: Eq,
Updates the signal by setting a new value.
Sourcepub fn update<R, U>(&self, compute: impl FnOnce(&T) -> U) -> R
pub fn update<R, U>(&self, compute: impl FnOnce(&T) -> U) -> R
Updates the signal by computing a new value from the old one.
Sourcepub fn update_mut<R, U>(&self, compute: impl FnOnce(&mut T) -> U) -> Rwhere
U: Into<UpdateSignalResult<T, R>>,
pub fn update_mut<R, U>(&self, compute: impl FnOnce(&mut T) -> U) -> Rwhere
U: Into<UpdateSignalResult<T, R>>,
Updates the signal by computing a new value from the old one.
The old value is mutable and can be reused to compute the new value.
Sourcepub fn force(&self, new_value: impl Into<T>)
pub fn force(&self, new_value: impl Into<T>)
Updates the signal by setting a new value.
Contrary to XSignal::set, the signal triggers even if the value didn’t change.
Trait Implementations§
Source§impl<V> From<&XSignal<V>> for MutableSignal<V>
impl<V> From<&XSignal<V>> for MutableSignal<V>
Source§impl<V> From<XSignal<V>> for MutableSignal<V>
impl<V> From<XSignal<V>> for MutableSignal<V>
impl<T: Send> Send for XSignal<T>
Safe because Javascript is single-threaded.
impl<T: Sync> Sync for XSignal<T>
Safe because Javascript is single-threaded.
Auto Trait Implementations§
impl<T> Freeze for XSignal<T>
impl<T> RefUnwindSafe for XSignal<T>
impl<T> Unpin for XSignal<T>
impl<T> UnwindSafe for XSignal<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more