pub struct Signal<T>{ /* private fields */ }Expand description
A reactive signal handle.
Allows reading, writing, and subscribing to changes.
Implements Copy for ergonomic use; all copies share the same underlying state.
SAFETY: The inner pointer is allocated via Box::leak and lives for the
entire program. This is safe in single-threaded WASM contexts where no
concurrent access can occur.
Implementations§
Source§impl<T> Signal<T>
Implementation of reactive signal operations.
impl<T> Signal<T>
Implementation of reactive signal operations.
Sourcepub fn new(value: T) -> Self
pub fn new(value: T) -> Self
Creates a new Signal with the given initial value.
The inner state is allocated via Box::leak and lives for the
remainder of the program. This is safe in single-threaded WASM
contexts where no concurrent access can occur.
§Arguments
T- The initial value of the signal.
§Returns
Signal<T>- A handle to the newly created reactive signal.
Sourcepub fn try_get(&self) -> Option<T>
pub fn try_get(&self) -> Option<T>
Attempts to return the current value of the signal without panicking.
§Returns
Some(T)- The current value if the borrow succeeds.None- If the inner value is already mutably borrowed.
Sourcepub fn subscribe<F>(&self, callback: F)where
F: FnMut() + 'static,
pub fn subscribe<F>(&self, callback: F)where
F: FnMut() + 'static,
Subscribes a callback to be invoked when the signal changes.
§Arguments
FnMut() + 'static- The callback to invoke when the signal changes.
Sourcepub fn replace_subscribe<F>(&self, callback: F)where
F: FnMut() + 'static,
pub fn replace_subscribe<F>(&self, callback: F)where
F: FnMut() + 'static,
Replaces all listeners with a single new callback.
Unlike subscribe, which appends a listener, this method clears any
existing listeners first and then adds the new one. This prevents
listener accumulation across re-renders: each signal is guaranteed
to have at most one active listener at any time, eliminating
cascading set() calls that would otherwise grow exponentially.
§Arguments
FnMut() + 'static- The callback to invoke when the signal changes.
Sourcepub fn clear_listeners(&self)
pub fn clear_listeners(&self)
Removes all subscribed listeners from this signal and marks it as
inactive. After calling this method, subsequent set() and
try_set() calls become complete no-ops: the value is not updated,
no listeners are invoked, and schedule_signal_update() is not
called. This is used during hook context cleanup when a match
arm switch discards old signals, ensuring that stale setInterval
closures referencing these signals become entirely harmless.
Sourcepub fn set(&self, value: T)
pub fn set(&self, value: T)
Sets the value of the signal and notifies listeners.
If the signal has been marked as inactive (via clear_listeners()),
this method is a complete no-op: the value is not updated, no
listeners are invoked, and no global update is scheduled.
If the new value is equal to the current value, no update is performed and no listeners are notified. This prevents unnecessary re-renders and avoids cascading no-op updates through intermediate signal chains.
§Arguments
T- The new value to assign to the signal.
Sourcepub fn set_silent(&self, value: T)
pub fn set_silent(&self, value: T)
Sets the value of the signal and notifies listeners without scheduling a global DOM update dispatch.
This is identical to set except it does not call
schedule_signal_update(), meaning no __euv_signal_update__ event
will be dispatched. Use this for internal bookkeeping signals whose
changes should not trigger DynamicNode re-renders.
§When to use
Prefer set in almost all cases. Only use set_silent when the
signal change is guaranteed not to affect any DynamicNode output
(e.g., internal guard flags, derived-value caches already at the
correct value, or within a with_suppressed_updates block where
the caller takes responsibility for batching the update).
If the new value is equal to the current value, no update is performed and no listeners are notified.
If the signal has been marked as inactive (via clear_listeners()),
this method is a complete no-op.
Sourcepub fn try_set(&self, value: T) -> bool
pub fn try_set(&self, value: T) -> bool
Attempts to set the value of the signal and notify listeners without panicking.
If the new value is equal to the current value, no update is performed.
§Arguments
T- The new value to assign to the signal.
§Returns
bool-trueif the value was successfully updated and listeners were notified,falseif unchanged or inactive.
Trait Implementations§
Source§impl<T> AsNode for Signal<T>
Converts a signal into a reactive text virtual node.
impl<T> AsNode for Signal<T>
Converts a signal into a reactive text virtual node.
Source§fn as_node(&self) -> Option<VirtualNode>
fn as_node(&self) -> Option<VirtualNode>
VirtualNode, if possible.Source§impl<T> AsReactiveText for Signal<T>
Converts a signal into a reactive text node with listener wiring.
impl<T> AsReactiveText for Signal<T>
Converts a signal into a reactive text node with listener wiring.
Source§fn as_reactive_text(&self) -> VirtualNode
fn as_reactive_text(&self) -> VirtualNode
VirtualNode::Text with reactive signal binding.Source§impl<T> Deref for Signal<T>
Prevents direct dereference of a signal to enforce explicit API usage.
impl<T> Deref for Signal<T>
Prevents direct dereference of a signal to enforce explicit API usage.
Source§impl<T> DerefMut for Signal<T>
Prevents direct mutable dereference of a signal to enforce explicit API usage.
impl<T> DerefMut for Signal<T>
Prevents direct mutable dereference of a signal to enforce explicit API usage.
Source§impl<T> IntoNode for Signal<T>
Converts a signal into a reactive text virtual node via IntoNode.
impl<T> IntoNode for Signal<T>
Converts a signal into a reactive text virtual node via IntoNode.
Source§fn into_node(self) -> VirtualNode
fn into_node(self) -> VirtualNode
VirtualNode by consuming it.Source§impl IntoReactiveString for Signal<String>
Converts a string signal into a reactive string by resolving its current value.
impl IntoReactiveString for Signal<String>
Converts a string signal into a reactive string by resolving its current value.
Source§fn into_reactive_string(self) -> String
fn into_reactive_string(self) -> String
Source§impl IntoReactiveString for Signal<bool>
Converts a bool signal into a reactive string by resolving its current value.
impl IntoReactiveString for Signal<bool>
Converts a bool signal into a reactive string by resolving its current value.
Source§fn into_reactive_string(self) -> String
fn into_reactive_string(self) -> String
Source§impl IntoReactiveValue for Signal<String>
Converts a string signal into a reactive attribute value.
impl IntoReactiveValue for Signal<String>
Converts a string signal into a reactive attribute value.
Source§fn into_reactive_value(self) -> AttributeValue
fn into_reactive_value(self) -> AttributeValue
AttributeValue, wrapping signals
for reactive updates or converting static values to text.Source§impl IntoReactiveValue for Signal<bool>
Converts a mutable bool signal into a reactive attribute value.
impl IntoReactiveValue for Signal<bool>
Converts a mutable bool signal into a reactive attribute value.
The signal is mapped to a Signal<String> that yields "true" or "false",
enabling boolean attributes like checked to reactively update the DOM.
Source§fn into_reactive_value(self) -> AttributeValue
fn into_reactive_value(self) -> AttributeValue
AttributeValue, wrapping signals
for reactive updates or converting static values to text.impl<T> Copy for Signal<T>
Copies the signal, sharing the same inner state.
A Signal is just a raw pointer; copying it is a trivial bitwise copy.