pub struct Signal<T> { /* private fields */ }Expand description
Reactive state shared by browser expressions.
Create a signal with signal during rendering. Runtime expressions
can read and write it. When its value changes, browser expressions
that read it run again. Cloning a signal is cheap and refers to the
same state.
On the server, get and read track the
signal as a dependency. A change re-renders the enclosing shard, or the
page if there is no shard. Use get_untracked or
read_untracked to read without this dependency.
Validate values read on the server because the client can supply them.
Implementations§
Source§impl<T> Signal<T>
impl<T> Signal<T>
Sourcepub fn read(&self) -> &T
pub fn read(&self) -> &T
Borrows the current value, tracking the signal as a dependency of the body reading it.
A change re-renders the enclosing shard, or the page if there is no shard. Repeated reads create only one dependency.
§Panics
Panics outside an active rendering scope or runtime expression.
Sourcepub fn read_untracked(&self) -> &T
pub fn read_untracked(&self) -> &T
Borrows the current value without tracking the signal.
Outside runtime expressions, this creates no dependency and needs no rendering scope.
Source§impl<T> Signal<T>where
T: Clone,
impl<T> Signal<T>where
T: Clone,
Sourcepub fn get_untracked(&self) -> T
pub fn get_untracked(&self) -> T
Clones the current value without tracking the signal.
Uses the same tracking rules as read_untracked.
Trait Implementations§
Source§impl<T> Surrogated for Signal<T>
impl<T> Surrogated for Signal<T>
type Surrogate = SignalSurrogate<T>
fn into_surrogate(self) -> Self::Surrogate
Source§impl<'__lifetime, T> Surrogated for &'__lifetime Signal<T>
impl<'__lifetime, T> Surrogated for &'__lifetime Signal<T>
type Surrogate = &'__lifetime SignalSurrogate<T>
fn into_surrogate(self) -> Self::Surrogate
Source§impl<'__lifetime, T> Surrogated for &'__lifetime mut Signal<T>
impl<'__lifetime, T> Surrogated for &'__lifetime mut Signal<T>
type Surrogate = &'__lifetime mut SignalSurrogate<T>
fn into_surrogate(self) -> Self::Surrogate
Auto Trait Implementations§
impl<T> Freeze for Signal<T>
impl<T> RefUnwindSafe for Signal<T>where
Arc<T>: RefUnwindSafe,
impl<T> Send for Signal<T>
impl<T> Sync for Signal<T>
impl<T> Unpin for Signal<T>
impl<T> UnsafeUnpin for Signal<T>where
Arc<T>: UnsafeUnpin,
impl<T> UnwindSafe for Signal<T>where
Arc<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
impl<T> CloneAny for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> SignalValue for Twhere
T: Surrogated,
<T as Surrogated>::Surrogate: DeserializeOwned,
&'a T: for<'a> Surrogated,
<&'a T as Surrogated>::Surrogate: for<'a> Serialize,
impl<T> SignalValue for Twhere
T: Surrogated,
<T as Surrogated>::Surrogate: DeserializeOwned,
&'a T: for<'a> Surrogated,
<&'a T as Surrogated>::Surrogate: for<'a> Serialize,
Source§type Surrogate<'a> = <&'a T as Surrogated>::Surrogate
where
T: 'a
type Surrogate<'a> = <&'a T as Surrogated>::Surrogate where T: 'a
Source§fn surrogate(&self) -> <T as SignalValue>::Surrogate<'_>
fn surrogate(&self) -> <T as SignalValue>::Surrogate<'_>
Source§fn from_value(value: &Value) -> Option<T>
fn from_value(value: &Value) -> Option<T>
None if
the surrogate does not fit this type.