Macro gxi::set_state [−][src]
set_state!() { /* proc-macro */ }
Expand description
manages state ownership, borrow, and async event handlers to reduce boiler plate code
args
-
expression
- if expression is of type closure, then automatic borrow is avoided
- otherwise dependent variables are cloned and borrowed to scope.
e.g
ⓘset_state!(*counter+=1);
is equal to
ⓘset_state!(|_| { *counter+=1; }, [ref counter])
or
ⓘset_state!(|_| { *counter.as_ref().borrow_mut()+=1; }, [counter])
-
variables
on which closure depends on
In case variables not are specified then dependencies are automatically guessed. If first expression is of type closure then automatic guessing is avoided, due to complexity of closure expressions.
e.g
ⓘ
pub fn app() -> StrongNodeType {
let counter = gxi::State::new(2);
let click_handler = set_state!(|_| {
*counter += 1;
}, [ref counter]);
return gxi! {
div [
h1 ( const on_click = click_handler, inner_html = &counter.to_string()[..] ),
button ( on_click = set_state!(counter += 1) )
]
}
}
move is automatically added to resultant closure regardless of expression type
dependency prefix
passed dependencies can be prefixed with keywords to reduce boiler plate code
ref
=>.as_ref().borrow_mut()