XSignal

Struct XSignal 

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

Source

pub fn derive<U>( &self, name: impl Into<XString>, to: impl Fn(&T) -> U + 'static, from: impl Fn(&T, &U) -> Option<T> + 'static, ) -> XSignal<U>
where T: Debug + 'static, U: Debug + Eq + 'static,

Source

pub fn view<U>( &self, name: impl Into<XString>, to: impl Fn(&T) -> U + 'static, ) -> XSignal<U>
where T: Debug + 'static, U: Debug + Eq + 'static,

Source§

impl<T> XSignal<T>

Source

pub fn downgrade(&self) -> XSignalWeak<T>

Source§

impl<T> XSignal<T>

Source

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.

Source

pub fn add_subscriber(&self, closure: impl Fn(T) + 'static) -> Consumers
where T: Clone + 'static,

Registers a callback that will trigger when the signal is updated.

Source

pub fn get_value_untracked(&self) -> T
where T: Clone,

Gets the current value of the signal.

Reactive behavior should use XSignal::add_subscriber.

Source§

impl<T: Debug + 'static> XSignal<T>

Source

pub fn set(&self, new_value: impl Into<T>)
where T: Eq,

Updates the signal by setting a new value.

Source

pub fn update<R, U>(&self, compute: impl FnOnce(&T) -> U) -> R
where U: Into<UpdateSignalResult<Option<T>, R>>,

Updates the signal by computing a new value from the old one.

Source

pub fn update_mut<R, U>(&self, compute: impl FnOnce(&mut T) -> U) -> R
where 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.

Source

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<T> Clone for XSignal<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for XSignal<T>

Source§

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

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

impl<T> Deref for XSignal<T>

Source§

type Target = XSignalInner<T>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<V> From<&XSignal<V>> for MutableSignal<V>

Source§

fn from(signal: &XSignal<V>) -> Self

Converts to this type from the input type.
Source§

impl<V> From<XSignal<V>> for MutableSignal<V>

Source§

fn from(signal: XSignal<V>) -> Self

Converts to this type from the input type.
Source§

impl<T: Send> Send for XSignal<T>

Safe because Javascript is single-threaded.

Source§

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> 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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 = Infallible

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<T> UpdateAndReturn for T

Source§

type NewValue = T

Source§

fn and_return<R>( self, result: R, ) -> UpdateSignalResult<<T as UpdateAndReturn>::NewValue, R>