Skip to main content

Signal

Struct Signal 

Source
pub struct Signal<T>
where T: Clone + PartialEq + 'static,
{ /* 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>
where T: Clone + PartialEq + 'static,

Implementation of reactive signal operations.

Source

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: Clone + PartialEq + 'static - The initial value of the signal.
§Returns
  • Self - A handle to the newly created reactive signal.
Source

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: Clone + PartialEq + 'static - The current value of the signal.
Source

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.
Source

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.

When called inside batch, the dispatch is deferred (dirty slots are still marked precisely), and the outermost set() call outside the suppressed scope will trigger the actual dispatch cycle.

§Arguments
  • T: Clone + PartialEq + 'static - The new value to assign to the signal.
Source§

impl<T> Signal<T>
where T: Clone + PartialEq + 'static,

Source

pub fn get_inner(&self) -> usize

Source

pub fn get__marker(&self) -> PhantomData<fn() -> T>

Source§

impl<T> Signal<T>
where T: Clone + PartialEq + 'static,

Source

pub fn new(inner: usize, _marker: PhantomData<fn() -> T>) -> Self

Trait Implementations§

Source§

impl<T> AsReactiveText for Signal<T>
where T: Clone + PartialEq + Display + 'static,

Converts a signal into a reactive text node with listener wiring.

Source§

fn as_reactive_text(&self) -> VirtualNode

Creates a reactive text node that auto-updates when the signal changes.

Internally creates a bridge Signal<String> that subscribes to the source signal and updates the text content on every change.

§Returns
  • VirtualNode - A text virtual node with reactive signal binding.
Source§

impl<T> Clone for Signal<T>
where T: Clone + PartialEq + 'static,

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.
Source§

fn clone(&self) -> Self

Clones the Signal by reusing shared, cheap-to-clone state where possible.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Copy for Signal<T>
where T: Clone + PartialEq + 'static,

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> Debug for Signal<T>
where T: Clone + PartialEq + 'static,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for Signal<T>
where T: Clone + Default + PartialEq + 'static,

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 with T::default().
Source§

fn default() -> Self

Constructs a default Signal value.

Source§

impl<T> Eq for Signal<T>
where T: Clone + PartialEq + 'static + Eq,

Source§

impl From<Signal<String>> for AttributeValue

Converts a string signal into a reactive attribute value.

Source§

fn from(signal: Signal<String>) -> Self

Converts this string signal into an AttributeValue::Signal.

§Returns
  • AttributeValue - A signal-backed attribute value.
§Arguments
  • Signal<String> - Input value to convert from.
Source§

impl<T> From<Signal<T>> for VirtualNode
where T: Clone + PartialEq + Display + 'static,

Converts a signal into a reactive text virtual node.

Source§

fn from(signal: Signal<T>) -> Self

Converts this signal into a reactive text virtual node.

§Returns
  • VirtualNode - A reactive text virtual node.
§Arguments
  • Signal<T> - Input value to convert from.
Source§

impl From<Signal<bool>> for AttributeValue

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 from(signal: Signal<bool>) -> Self

Converts this bool signal into an AttributeValue via string mapping.

§Returns
  • AttributeValue - A signal-backed attribute value yielding "true" or "false".
§Arguments
  • Signal<bool> - Input value to convert from.
Source§

impl<T> Hash for Signal<T>
where T: Clone + PartialEq + 'static + Hash,

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> Ord for Signal<T>
where T: Clone + PartialEq + 'static + Ord,

Source§

fn cmp(&self, other: &Signal<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

fn clamp_to<R>(self, range: R) -> Self
where Self: Sized, R: ClampBounds<Self>,

🔬This is a nightly-only experimental API. (clamp_to)
Restrict a value to a certain range. Read more
Source§

impl<T> PartialEq for Signal<T>
where T: Clone + PartialEq + 'static + PartialEq,

Source§

fn eq(&self, other: &Signal<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T> PartialOrd for Signal<T>
where T: Clone + PartialEq + 'static + PartialOrd,

Source§

fn partial_cmp(&self, other: &Signal<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<T> StructuralPartialEq for Signal<T>
where T: Clone + PartialEq + 'static + PartialEq,

Auto Trait Implementations§

§

impl<T> Freeze for Signal<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> RefUnwindSafe for Signal<T>
where PhantomData<fn() -> T>: RefUnwindSafe,

§

impl<T> Send for Signal<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Sync for Signal<T>
where PhantomData<fn() -> T>: Sync,

§

impl<T> Unpin for Signal<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for Signal<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Signal<T>
where PhantomData<fn() -> T>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more