pub struct Signal<T>{ /* private fields */ }Expand description
A reactive signal handle.
Allows reading, writing, and subscribing to changes.
Implements Clone and Copy for ergonomic use; all copies share the same
underlying state. The inner state is heap-allocated via Box and accessed
through a raw pointer stored as a usize. The allocation is tracked in a
global registry for lifecycle management. The Copy semantics are safe
because only the pointer address is copied — the actual heap allocation
is owned by the registry.
Implementations§
Source§impl<T> Signal<T>
Implementation of reactive signal operations.
impl<T> Signal<T>
Implementation of reactive signal operations.
Sourcepub fn create(value: T) -> Self
pub fn create(value: T) -> Self
Creates a new Signal with the given initial value.
Allocates SignalInner<T> on the heap via Box, stores the raw pointer
address, and registers it in the global registry for lifecycle tracking.
§Arguments
T- The initial value of the signal.
§Returns
Self- A handle to the newly created reactive signal.
Sourcepub fn get(&self) -> T
pub fn get(&self) -> T
Returns the current value of the signal.
Directly reads the value from the heap-allocated inner state via raw pointer dereference. No runtime borrow checking overhead.
If the signal has been marked inactive (alive == false), returns the
last stored value without registering tracking dependencies. This
ensures that stale async callbacks (e.g., orphaned setInterval)
holding a Signal copy can still call .get() safely without
triggering side effects or panics.
If a tracking context is active (i.e., a DynamicNode is being rendered), automatically registers the current dynamic node as a dependent of this signal for precise reactive updates.
§Returns
T- The current value of the signal.
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 set(&self, value: T)
pub fn set(&self, value: T)
Sets the value of the signal and notifies listeners.
Uses precise dirty marking: only dynamic nodes that depend on this signal are marked dirty, avoiding full broadcast.
§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.
§Arguments
T- The new value to assign to the signal.
Sourcepub fn set_untracked(&self, value: T)
pub fn set_untracked(&self, value: T)
Sets the value of the signal without notifying listeners or scheduling a DOM update. This is useful for breaking circular watch dependencies where two signals watch each other and would otherwise recurse infinitely.
If the signal has been marked inactive (alive == false), this is a
no-op, consistent with set() behavior for dead signals.
§Arguments
T- The new value to assign to the signal.
Trait Implementations§
Source§impl<T> Clone for Signal<T>
Clones the signal, sharing the same inner state.
impl<T> Clone for Signal<T>
Clones the signal, sharing the same inner state.
Since Signal is Copy, this simply returns *self.
§Returns
Self: A copy of the signal handle sharing the same inner state.
impl<T> Copy for Signal<T>
Copies the signal, sharing the same inner state.
Safe because only the inner address (a usize) is copied;
the actual heap allocation is owned by the global signal registry.
Source§impl<T> Default for Signal<T>
Provides a safe default for Signal<T> by creating a valid signal
initialized with T::default().
impl<T> Default for Signal<T>
Provides a safe default for Signal<T> by creating a valid signal
initialized with T::default().
This prevents the creation of invalid signals with inner = 0 (null
pointer), which would cause a panic when .get() is called.
§Returns
Self: A valid signal initialized withT::default().
impl<T> Eq for Signal<T>
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
Converts this signal into a reactive text virtual node.
§Returns
VirtualNode- A reactive text virtual node.
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
Resolves the current value of this bool signal as a string.
§Returns
String- The current boolean value as"true"or"false".
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
Converts this string signal into an AttributeValue::Signal.
§Returns
AttributeValue- A signal-backed attribute value.
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
Converts this bool signal into an AttributeValue via string mapping.
§Returns
AttributeValue- A signal-backed attribute value yielding"true"or"false".