From 1a714268064800bf59cc70d35017ed6b7b39ca33 Mon Sep 17 00:00:00 2001 From: Jeremy Wall Date: Fri, 18 Aug 2023 17:12:48 -0400 Subject: [PATCH] Update documentation a bit. --- README.md | 8 ++++---- wasm-web-component/src/lib.rs | 9 +++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 489f1a3..c6a2035 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ --> # An experiment in Rust Web Assembly Web Components -This set of crates should not be considered production ready. Web Assembly is not +This set of crates should not be considered production ready. WebAssembly is not quite ready for general use in a Web Component. Getting this to work involved -something of a Rub Goldberg machine involving a Javascript shim and a wasm_bindgen -Rust shim with a several traits. The boilerplate is generated using a proc-macro -to make it more generally reusable. \ No newline at end of file +something of a Rub Goldberg machine involving a Javascript shim and a wasm\_bindgen +Rust shim with several traits. The boilerplate is generated using a proc-macro +to make it more generally reusable. diff --git a/wasm-web-component/src/lib.rs b/wasm-web-component/src/lib.rs index 7974571..e40500e 100644 --- a/wasm-web-component/src/lib.rs +++ b/wasm-web-component/src/lib.rs @@ -46,18 +46,26 @@ pub trait WebComponentDef: IntoWasmAbi + Default { /// Each method is optional. You only need to implement the ones /// you want to specify behavior for. pub trait WebComponentBinding: WebComponentDef { + /// Called when the web component is connected to the DOM. + /// This is when you should do any setup like attaching a ShadowDom + /// or appending elements. fn connected(&self, _element: &HtmlElement) { // noop } + /// Called when the web component is disconnected from the DOM. fn disconnected(&self, _element: &HtmlElement) { // noop } + /// Called When the web component is moved to a new document. fn adopted(&self, _element: &HtmlElement) { // noop } + /// Called when one of the observed attributes has changed. + /// the observedc attributes are listed in the observed_attrs argument to the + /// `#[web_component(observed_attrs = "['attr1', 'attr2']")` attribute. fn attribute_changed( &self, _element: &HtmlElement, @@ -68,6 +76,7 @@ pub trait WebComponentBinding: WebComponentDef { // noop } + /// Top level event handler for this custome element. fn handle_event(&self, _element: &HtmlElement, _event: &Event) { // noop }