Setup event handling scaffolding

This commit is contained in:
Jeremy Wall 2022-10-09 15:51:31 -04:00
parent 94e8ee07c6
commit e1d1b2c80b
2 changed files with 13 additions and 0 deletions

View File

@ -143,6 +143,10 @@ fn expand_struct_trait_shim(struct_name: &Ident, observed_attrs: Literal) -> syn
attributeChangedCallback(name, oldValue, newValue) {{
this._impl.attribute_changed_impl(this, name, oldValue, newValue);
}}
handleComponentEvent(evt) {{
this._impl.handle_component_event_impl(this, evt);
}}
}}
customElements.define(\"{element_name}\", {name});
var element = customElements.get(\"{element_name}\");
@ -211,6 +215,11 @@ fn expand_wasm_shim(struct_name: &Ident) -> syn::ItemImpl {
use #trait_path;
self.attribute_changed(element, name, old_value, new_value);
}
pub fn handle_component_event_impl(&self, element: &web_sys::HtmlElement, event: &web_sys::Event) {
use #trait_path;
self.handle_event(element, event);
}
}
}
}

View File

@ -67,6 +67,10 @@ pub trait WebComponentBinding: WebComponentDef {
) {
// noop
}
fn handle_event(&self, _element: &HtmlElement, _event: &Event) {
// noop
}
}
/// Marker trait used in the generated shims to assert that their are Rust implemtntations