Macro dominator_helpers::make_custom_event_serde[][src]

macro_rules! make_custom_event_serde {
    ($type:literal, $name:ident, $data:ident) => { ... };
}
Expand description

first arg is name of the new struct to create second arg is literal name of the event third arg is the data structure.

the data structure needs to already be defined and derive Deserialize

requires that the serde_wasm_bindgen crate be installed however, since this is only a macro, there’s no need to feature-gate it here Example:

JS (e.g. from a CustomElement)

this.dispatchEvent(new CustomEvent('todo-input', {
    detail: {label: value}
}));

Rust - first register the event

#[derive(Deserialize)]
pub struct TodoInputEventData {
    pub label: String
}
make_custom_event_serde!("todo-input", TodoInputEvent, TodoInputEventData);

then use it

html!("todo-custom", {
    .event(|event:TodoInputEvent| {
        //event.data() is a TodoInputEventData
        let label:&str = event.data().label;
    })
})