mirror of
https://github.com/zaphar/wasm-web-components.git
synced 2025-07-21 19:40:30 -04:00
docs: Update docs with event handling information.
This commit is contained in:
parent
f41a9d3100
commit
bb60556f29
@ -16,7 +16,8 @@ use web_sys::{window, Element, Event, HtmlElement, Window};
|
||||
/// It supports three optional attributes `name = value` parameters.
|
||||
/// * `class_name = "ClassName"` - The class name to use for the javascript shim. If not provided uses the structs name instead.
|
||||
/// * `element_name = "class-name"` - A valid custom element name to use for the element. if not proviced derives it from the class name.
|
||||
/// * `observed_attrs = "['attr1', attr2']"` - A javascript array with a list of observed attributes for this compoment. Defaults to "[]".
|
||||
/// * `observed_attrs = "['attr1', 'attr2']"` - A javascript array with a list of observed attributes for this compoment. Defaults to "[]".
|
||||
/// * `observed_events = "['click', 'change']"` - A javascript array with a list of observed event types for this compoment. Defaults to "[]".
|
||||
///
|
||||
/// It will also create a `Self::define_once` method that will define the WebComponent exactly
|
||||
/// once.
|
||||
@ -28,6 +29,7 @@ use web_sys::{window, Element, Event, HtmlElement, Window};
|
||||
/// class_name = "MyElement",
|
||||
/// element_name = "my-element",
|
||||
/// observed_attrs = "['class']"
|
||||
/// observed_events = "['click']"
|
||||
/// )]
|
||||
/// pub struct MyElementImpl {}
|
||||
///
|
||||
@ -65,6 +67,10 @@ use web_sys::{window, Element, Event, HtmlElement, Window};
|
||||
/// )));
|
||||
/// element.append_child(&node).unwrap();
|
||||
/// }
|
||||
///
|
||||
/// fn handle_event(&self, element: &HtmlElement, event: &Event)) {
|
||||
/// // handle this event
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// pub fn define_me() {
|
||||
@ -177,7 +183,7 @@ pub trait WebComponentBinding: WebComponentDef {
|
||||
// noop
|
||||
}
|
||||
|
||||
/// Top level event handler for this custome element.
|
||||
/// Top level event handler for this custom element.
|
||||
fn handle_event(&self, _element: &HtmlElement, _event: &Event) {
|
||||
// noop
|
||||
}
|
||||
@ -414,6 +420,8 @@ mod tests {
|
||||
assert_eq!(ThisElement::element_name(), "this-old-element");
|
||||
}
|
||||
|
||||
// TODO(jwall): Tests for event handling
|
||||
|
||||
// TODO(jwall): Benchmarks for TemplateElements?
|
||||
#[cfg(feature = "HtmlTemplateElement")]
|
||||
#[wasm_bindgen_test]
|
||||
|
Loading…
x
Reference in New Issue
Block a user