Struct maple_core::reactive::Signal[][src]

pub struct Signal<T: 'static> { /* fields omitted */ }

State that can be set.

Example

use maple_core::prelude::*;

let state = Signal::new(0);
assert_eq!(*state.get(), 0);

state.set(1);
assert_eq!(*state.get(), 1);

Implementations

impl<T: 'static> Signal<T>[src]

pub fn new(value: T) -> Self[src]

Creates a new signal with the given value.

Example

let state = Signal::new(0);

pub fn set(&self, new_value: T)[src]

Set the current value of the state.

This will notify and update any effects and memos that depend on this value.

Example


let state = Signal::new(0);
assert_eq!(*state.get(), 0);

state.set(1);
assert_eq!(*state.get(), 1);

pub fn handle(&self) -> StateHandle<T>[src]

Get the StateHandle associated with this signal.

This is a shortcut for (*signal).clone().

pub fn into_handle(self) -> StateHandle<T>[src]

Consumes this signal and returns its underlying StateHandle.

pub fn trigger_subscribers(&self)[src]

Calls all the subscribers without modifying the state. This can be useful when using patterns such as inner mutability where the state updated will not be automatically triggered. In the general case, however, it is preferable to use Signal::set instead.

Methods from Deref<Target = StateHandle<T>>

pub fn get(&self) -> Rc<T>[src]

Get the current value of the state.

pub fn get_untracked(&self) -> Rc<T>[src]

Get the current value of the state, without tracking this as a dependency if inside a reactive context.

Example

use maple_core::prelude::*;

let state = Signal::new(1);

let double = create_memo({
    let state = state.clone();
    move || *state.get_untracked() * 2
});

assert_eq!(*double.get(), 2);

state.set(2);
// double value should still be old value because state was untracked
assert_eq!(*double.get(), 2);

Trait Implementations

impl<T: 'static> Clone for Signal<T>[src]

impl<T: Debug> Debug for Signal<T>[src]

impl<T: 'static> Deref for Signal<T>[src]

type Target = StateHandle<T>

The resulting type after dereferencing.

impl<T: PartialEq> PartialEq<Signal<T>> for Signal<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Signal<T>

impl<T> !Send for Signal<T>

impl<T> !Sync for Signal<T>

impl<T> Unpin for Signal<T>

impl<T> !UnwindSafe for Signal<T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.