pub struct ReadSignal<T> { /* private fields */ }
Expand description

A read-only Signal.

Unlike Rust’s shared-reference (&T), the underlying data is not immutable. The data can be updated with the corresponding Signal (which has mutable access) and will show up in the ReadSignal as well.

A ReadSignal can be simply obtained by dereferencing a Signal. In fact, every Signal is a ReadSignal with additional write abilities!

Example

let signal: &Signal<i32> = create_signal(cx, 123);
let read_signal: &ReadSignal<i32> = &*signal;

Implementations

Get the current value of the state. When called inside a reactive scope, calling this will add itself to the scope’s dependencies.

Example
let state = create_signal(cx, 0);
assert_eq!(*state.get(), 0);

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

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

Example
let state = create_signal(cx, 1);
let double = create_memo(cx, || *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);

Creates a mapped ReadSignal. This is equivalent to using create_memo.

Example
let state = create_signal(cx, 1);
let double = state.map(cx, |&x| x * 2);
assert_eq!(*double.get(), 2);

state.set(2);
assert_eq!(*double.get(), 4);

When called inside a reactive scope, calling this will add itself to the scope’s dependencies.

To both track and get the value of the signal, use ReadSignal::get instead.

Trait Implementations

Call the ReadSignal::track method.
Formats the value using the given formatter. Read more
Formats the value using the given formatter. Read more
Feeds this value into the given Hasher. Read more
Feeds a slice of this type into the given Hasher. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Compare self to key and return true if they are equal.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Called during the initial render when creating the DOM nodes. Should return a View.
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.