New abstraction over Hook::bind, all of the following lines are equivalent:
// no sugar
let onclick = counter.bind(|counter, _| *counter += 1);
// old bind! macro
bind! {
counter:
let onclick = move |_| *counter += 1;
}
// new event! macro long form
let onclick = event!(|counter, _| *counter += 1);
// new event! macro skipping event in closure
let onclick = event!(|counter| *counter += 1);
// new event! macro shorthand
let onclick = event!(*counter += 1);
The shorthand variant works only if the expression begins either with the same identifier as the &Hook to the state, or deref asterisk followed by the same identifier like in the example alone. Aside from assignment like above, this makes the following scenarios very ergonomic:
/// assigning a field on a struct
let onclick = event!(state.some_field = value);
/// calling a method
let onclick = event!(state.some_method());
New abstraction over
Hook::bind
, all of the following lines are equivalent:The shorthand variant works only if the expression begins either with the same identifier as the
&Hook
to the state, or deref asterisk followed by the same identifier like in the example alone. Aside from assignment like above, this makes the following scenarios very ergonomic: