pub struct Signal<T> { /* private fields */ }Implementations§
Source§impl<T> Signal<T>where
T: 'static,
impl<T> Signal<T>where
T: 'static,
Sourcepub fn new(initial: T) -> Self
pub fn new(initial: T) -> Self
Creates a new signal with the given initial value.
A signal is a reactive value that can be read and updated. When a signal is updated, all function components that read the signal will be re-run to reflect the new value.
The signal is removed when the component which created it goes out of scope.
§Example
use rustolio_web::prelude::*;
let s = Signal::new("Hello World".to_string());
div! {
class: "container",
move || s.value(),
};§Caveats
All caveats will throw an runtime error in debug mode.
§Immutable Signals
When creating a signal, it is important to ensure that the signal is read in a function component (e.g., move || s.value()). If this is not done, the signal itself will be recreated on every update, making it effectively immutable.
Dont do this:
use rustolio_web::prelude::*;
let s = Signal::new("Hello World".to_string());
div! {
s.value()
};Do this instead:
use rustolio_web::prelude::*;
let s = Signal::new("Hello World".to_string());
div! {
move || s.value()
};
// OR
move || div! {
s.value()
};§Breaking Signals
When reading a signal value, it is important to ensure that the next component is not a function component. This would break the signal’s updater, as it would replace the component without notifying the signal’s updater.
Dont do this:
use rustolio_web::prelude::*;
let s = Signal::new("Hello World".to_string());
let s1 = Signal::new("Hello World 2".to_string());
div! {
move || {
let value = s.value();
move || div! {
format!("S: {} - S1: {}", value, s1.value())
}
}
};Do this instead:
use rustolio_web::prelude::*;
let s = Signal::new("Hello World".to_string());
let s1 = Signal::new("Hello World 2".to_string());
div! {
move || {
let value = s.value();
div! {
move || div! {
format!("S: {} - S1: {}", value, s1.value())
}
}
}
};Sourcepub fn always_mutable(initial: T) -> Self
pub fn always_mutable(initial: T) -> Self
Creates the Signal (same as Self::new) but the check for immutablility will alway succeed.
This can be useful for Signal-Wrapper which are allowed the be read in the same scope.
Trait Implementations§
Source§impl<T> From<GlobalSignal<T>> for Signal<T>where
T: Clone + 'static,
impl<T> From<GlobalSignal<T>> for Signal<T>where
T: Clone + 'static,
Source§fn from(val: GlobalSignal<T>) -> Self
fn from(val: GlobalSignal<T>) -> Self
Source§impl<S, T> From<GlobalWrapper<S>> for Signal<T>
impl<S, T> From<GlobalWrapper<S>> for Signal<T>
Source§fn from(val: GlobalWrapper<S>) -> Self
fn from(val: GlobalWrapper<S>) -> Self
Source§impl<T> SignalBase<T> for Signal<T>
impl<T> SignalBase<T> for Signal<T>
Source§impl<T> SignalGetter<T> for Signal<T>where
T: Clone + 'static,
impl<T> SignalGetter<T> for Signal<T>where
T: Clone + 'static,
Source§impl<T> SignalSetter<T> for Signal<T>where
T: PartialEq + 'static,
impl<T> SignalSetter<T> for Signal<T>where
T: PartialEq + 'static,
Source§impl<T> SignalUpdater<T> for Signal<T>where
T: 'static,
impl<T> SignalUpdater<T> for Signal<T>where
T: 'static,
Source§fn update<U>(&self, updater: impl FnOnce(&mut T) -> U) -> U
fn update<U>(&self, updater: impl FnOnce(&mut T) -> U) -> U
Source§fn set_unchecked(&self, value: impl Into<T>)
fn set_unchecked(&self, value: impl Into<T>)
impl<T> Copy for Signal<T>
impl<T: Eq> Eq for Signal<T>
impl<T> StructuralPartialEq for Signal<T>
Auto Trait Implementations§
impl<T> Freeze for Signal<T>
impl<T> RefUnwindSafe for Signal<T>where
T: RefUnwindSafe,
impl<T> Send for Signal<T>where
T: Send,
impl<T> Sync for Signal<T>where
T: Sync,
impl<T> Unpin for Signal<T>where
T: Unpin,
impl<T> UnsafeUnpin for Signal<T>
impl<T> UnwindSafe for Signal<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.