Clone in a terminal:
Commit 86beb1c
Johan Mattsson - 2026-06-28T12:24:51+00:00
86beb1c2a4803a51afd918ec95f3b036d35e5928johan.mattsson.m@gmail.com

Fix init state functions The rust self for component.

Changed files (1)

Diff

diff --git a/src/init.rs b/src/init.rsindex 6ea5a9b..5f014c3 100644--- a/src/init.rs+++ b/src/init.rs@@ -74,42 +74,41 @@ fn generate_create_component_fn(     tag: LitStr,     init_state_fn: &str, ) -> proc_macro2::TokenStream {-    let js_init = String::from(-        r#"-            let componentId = -1;--            return class extends HTMLElement {-                connectedCallback() {-                    if (componentId == -1) {-                        componentId = __INIT_CALLBACK;-                    }+    let expanded = quote! {+        #[allow(non_snake_case)]+        pub fn #name() { // createComponentTheStructName+            let wasm_id = 0; -                    counterComponentConnect(this, componentId);-                }+            let js_init = String::from(+                r#"+                    let componentId = -1; -                disconnectedCallback() {-                    counterComponentDisconnect(this, componentId);-                }+                    return class extends HTMLElement {+                        connectedCallback() {+                            if (componentId == -1) {+                                componentId = __INIT_CALLBACK;+                            } -                attributeChangedCallback(name, oldValue, newValue) {-                    //callbacks.attributeChanged(this, name, oldValue, newValue);-                }+                            counterComponentConnect(this, componentId);+                        } -                static get observedAttributes() {-                    return [];-                }-            }-    "#,-    );+                        disconnectedCallback() {+                            counterComponentDisconnect(this, componentId);+                        } -    let js_init_with_state = js_init.replace("__INIT_CALLBACK", #init_state_fn);+                        attributeChangedCallback(name, oldValue, newValue) {+                            //callbacks.attributeChanged(this, name, oldValue, newValue);+                        } -    let expanded = quote! {-        #[allow(non_snake_case)]-        pub fn #name() { // createComponentTheStructName-            let wasm_id = 0;-            let class_init_fn = format!()-            let component = Function::new_no_args(r#"js_init_with_state"#);+                        static get observedAttributes() {+                            return [];+                        }+                    }+            "#,+            );++            let js_init_with_state = js_init.replace("__INIT_CALLBACK", #init_state_fn);+            let component = js_sys::Function::new_no_args(js_init_with_state.as_str());              let class = component.call0(&JsValue::NULL); 

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112