pub struct Signal<T> { /* private fields */ }Expand description
A piece of state that lives in the browser.
A signal is created with signal during a server render and read or
written in runtime expressions, where it is reactive: an expression
re-runs in the browser whenever a signal it read changes. A signal is
cheap to clone, and every clone is the same signal: runtime expressions
clone the signals they capture, so any number of them can capture one,
a component takes one as a &Signal<T> prop, and a shard takes one as
a Signal<T> parameter passed as $(signal).
A signal can also be read on the server, outside any runtime
expression. get and read are tracked
reads: they make the body’s content depend on the signal, so that a
change re-runs the page, or the innermost shard enclosing the read, with
the signal’s current value. get_untracked and
read_untracked read the value without that
dependency. Every value read on the server is untrusted user input,
chosen by the client like a shard argument.
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.
The body’s content is marked as depending on the signal, so the browser runtime re-runs the page, or the innermost shard enclosing the read, when the signal changes. Reading the same signal any number of times in one body marks its content once.
§Panics
Panics when called outside a page, layout, component, or shard body,
like signal.
Sourcepub fn read_untracked(&self) -> &T
pub fn read_untracked(&self) -> &T
Borrows the current value without tracking the signal.
A change to the signal does not re-run the body that read it this way. It can be called anywhere, not just inside a body.
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.
This is read_untracked for a value the
body wants to own.
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> 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.