Macro leptos::update_value
source · macro_rules! update_value { (|$ident:ident $(,)?| $body:expr) => { ... }; (move |$ident:ident $(,)?| $body:expr) => { ... }; (|$first:ident, $($rest:ident),+ $(,)? | $body:expr) => { ... }; (move |$first:ident, $($rest:ident),+ $(,)? | $body:expr) => { ... }; }
Expand description
Provides a simpler way to use
StoredValue::update_value
.
To use with signals, see the update
macro instead.
Note that the update!
macro also works with
StoredValue
. Use this macro if you would like to
distinguish between signals and stored values.
The general syntax looks like:
ⓘ
update_value!(|capture1, capture2, ...| body);
The variables within the ‘closure’ arguments are captured from the environment, and can be used within the body with the same name.
move
can also be added before the closure arguments to add move
to all
expanded closures.
§Examples
let a = store_value(1);
let b = store_value(2);
update_value!(|a, b| *a = *a + *b);
assert_eq!(a.get_value(), 3);
The update_value!
macro in the above example expands to:
ⓘ
a.update_value(|a| {
b.update_value(|b| *a = *a + *b)
})
If move
is added:
ⓘ
update_value!(move |a, b| *a = *a + *b + something_else)
Then all closures are also move
.
ⓘ
first.update_value(move |a| {
last.update_value(move |b| *a = *a + *b + something_else)
})