diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 2d00bf5..93a9bf9 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -133,7 +133,9 @@ fn expand_wc_struct_trait_shim( "class {name} extends HTMLElement {{ constructor() {{ super(); - this._impl = impl(); + var self = this; + self._impl = impl(); + self._impl.init(); }} connectedCallback() {{ diff --git a/wasm-web-component/src/lib.rs b/wasm-web-component/src/lib.rs index 1671827..e92bd3e 100644 --- a/wasm-web-component/src/lib.rs +++ b/wasm-web-component/src/lib.rs @@ -142,6 +142,11 @@ 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 during element construction. + fn init(&self, _element: &HtmlElement) { + // noop + } + /// 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.