Struct maple_core::reactive::Signal [−][src]
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]
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]
fn clone(&self) -> Self[src]
pub fn clone_from(&mut self, source: &Self)1.0.0[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.
fn deref(&self) -> &Self::Target[src]
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]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,