[][src]Macro dominator_helpers::make_custom_event_serde

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

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

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

then use it

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