pub struct SignalSetter<T>where
T: 'static,{ /* private fields */ }
Expand description
A wrapper for any kind of settable reactive signal: a WriteSignal
,
RwSignal
, or closure that receives a value and sets a signal depending
on it.
This allows you to create APIs that take any kind of SignalSetter<T>
as an argument,
rather than adding a generic F: Fn(T)
. Values can be set with the same
function call or set()
, API as other signals.
§Core Trait Implementations
.set()
(or calling the setter as a function) sets the signal’s value, and notifies all subscribers that the signal’s value has changed. to subscribe to the signal, and to re-run whenever the value of the signal changes.
§Examples
let (count, set_count) = create_signal(2);
let set_double_input = SignalSetter::map(move |n| set_count.set(n * 2));
// this function takes any kind of signal setter
fn set_to_4(setter: &SignalSetter<i32>) {
// ✅ calling the signal sets the value
// can be `setter(4)` on nightly
setter.set(4);
}
set_to_4(&set_count.into());
assert_eq!(count.get(), 4);
set_to_4(&set_double_input);
assert_eq!(count.get(), 8);
Implementations§
Source§impl<T> SignalSetter<T>where
T: 'static,
impl<T> SignalSetter<T>where
T: 'static,
Sourcepub fn map(mapped_setter: impl Fn(T) + 'static) -> SignalSetter<T>
pub fn map(mapped_setter: impl Fn(T) + 'static) -> SignalSetter<T>
Wraps a signal-setting closure, i.e., any computation that sets one or more reactive signals.
let (count, set_count) = create_signal(2);
let set_double_count = SignalSetter::map(move |n| set_count.set(n * 2));
// this function takes any kind of signal setter
fn set_to_4(setter: &SignalSetter<i32>) {
// ✅ calling the signal sets the value
// can be `setter(4)` on nightly
setter.set(4)
}
set_to_4(&set_count.into());
assert_eq!(count.get(), 4);
set_to_4(&set_double_count);
assert_eq!(count.get(), 8);
Sourcepub fn set(&self, value: T)
pub fn set(&self, value: T)
Calls the setter function with the given value.
let (count, set_count) = create_signal(2);
let set_double_count = SignalSetter::map(move |n| set_count.set(n * 2));
// this function takes any kind of signal setter
fn set_to_4(setter: &SignalSetter<i32>) {
// ✅ calling the signal sets the value
// can be `setter(4)` on nightly
setter.set(4);
}
set_to_4(&set_count.into());
assert_eq!(count.get(), 4);
set_to_4(&set_double_count);
assert_eq!(count.get(), 8);
Trait Implementations§
Source§impl<T> Clone for SignalSetter<T>
impl<T> Clone for SignalSetter<T>
Source§fn clone(&self) -> SignalSetter<T>
fn clone(&self) -> SignalSetter<T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T> Debug for SignalSetter<T>where
T: Debug + 'static,
impl<T> Debug for SignalSetter<T>where
T: Debug + 'static,
Source§impl<T> Default for SignalSetter<T>where
T: Default + 'static,
impl<T> Default for SignalSetter<T>where
T: Default + 'static,
Source§fn default() -> SignalSetter<T>
fn default() -> SignalSetter<T>
Returns the “default value” for a type. Read more
Source§impl<T> Fn(T) for SignalSetter<T>
impl<T> Fn(T) for SignalSetter<T>
Source§impl<T> FnMut(T) for SignalSetter<T>
impl<T> FnMut(T) for SignalSetter<T>
Source§impl<T> FnOnce(T) for SignalSetter<T>
impl<T> FnOnce(T) for SignalSetter<T>
Source§impl<T> From<RwSignal<T>> for SignalSetter<T>
impl<T> From<RwSignal<T>> for SignalSetter<T>
Source§fn from(value: RwSignal<T>) -> SignalSetter<T>
fn from(value: RwSignal<T>) -> SignalSetter<T>
Converts to this type from the input type.
Source§impl<T> From<WriteSignal<T>> for SignalSetter<T>
impl<T> From<WriteSignal<T>> for SignalSetter<T>
Source§fn from(value: WriteSignal<T>) -> SignalSetter<T>
fn from(value: WriteSignal<T>) -> SignalSetter<T>
Converts to this type from the input type.
Source§impl<T> PartialEq for SignalSetter<T>where
T: PartialEq + 'static,
impl<T> PartialEq for SignalSetter<T>where
T: PartialEq + 'static,
Source§impl<T> SignalSet for SignalSetter<T>
impl<T> SignalSet for SignalSetter<T>
impl<T> Copy for SignalSetter<T>
impl<T> Eq for SignalSetter<T>where
T: Eq + 'static,
impl<T> StructuralPartialEq for SignalSetter<T>where
T: 'static,
Auto Trait Implementations§
impl<T> Freeze for SignalSetter<T>
impl<T> !RefUnwindSafe for SignalSetter<T>
impl<T> !Send for SignalSetter<T>
impl<T> !Sync for SignalSetter<T>
impl<T> Unpin for SignalSetter<T>where
T: Unpin,
impl<T> !UnwindSafe for SignalSetter<T>
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
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<F> Directive<(HtmlElement<AnyElement>,), ()> for F
impl<F> Directive<(HtmlElement<AnyElement>,), ()> for F
Source§fn run(&self, el: HtmlElement<AnyElement>, _: ())
fn run(&self, el: HtmlElement<AnyElement>, _: ())
Calls the handler function
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
Compare self to
key
and return true
if they are equal.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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<F, T> IntoSignalSetter<T> for Fwhere
F: Fn(T) + 'static,
impl<F, T> IntoSignalSetter<T> for Fwhere
F: Fn(T) + 'static,
Source§fn mapped_signal_setter(self) -> SignalSetter<T>
fn mapped_signal_setter(self) -> SignalSetter<T>
👎Deprecated: Will be removed in
leptos v0.6
. Please use IntoSignalSetter::into_signal_setter()
instead.Consumes
self
, returning SignalSetter<T>
.Source§fn into_signal_setter(self) -> SignalSetter<T>
fn into_signal_setter(self) -> SignalSetter<T>
Consumes
self
, returning SignalSetter<T>
.