macro_rules! define_component {
(
name: $name:expr,
state: { $($field:ident : $type:ty = $default:expr),* $(,)? },
template: $template:expr
$(, styles: $styles:expr)?
$(, on_init: $on_init:expr)?
$(, on_destroy: $on_destroy:expr)?
$(,)?
) => { ... };
}Expand description
Define a component with Angular-like syntax.
§Example
ⓘ
define_component! {
name: "my-counter",
state: { count: i32 = 0 },
template: |state, ctx| {
col![
label!(format!("Count: {}", state.count)),
button!("+", { ctx.update(|s| s.count += 1); }),
]
},
styles: r#"
.counter { padding: 16px; }
"#,
on_init: |state| { println!("Init: {}", state.count); },
}