Commit eff2a45
Component update
Changed files (7)
modifiedCargo.lockmodifiedCargo.tomlmodifiedexamples/components/Cargo.lockmodifiedexamples/components/Cargo.tomlmodifiedexamples/components/src/lib.rsmodifiedsrc/lib.rsmodifiedsrc/prelude.rs
Diff
@@ -382,9 +382,7 @@ dependencies = [ [[package]] name = "kaja-callback-macro"-version = "0.1.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f991f9438ddafefdef1b5fb95a4a60f3bc834b419c27409d8e10a7839c47af8d"+version = "1.0.0" dependencies = [ "gloo", "proc-macro2",@@ -414,6 +412,7 @@ dependencies = [ "js-sys", "kaja-callback-macro", "kaja-html-macro",+ "kaja-web-component", "serde", "serde-wasm-bindgen 0.5.0", "wasm-bindgen",@@ -422,6 +421,20 @@ dependencies = [ ] [[package]]+name = "kaja-web-component"+version = "0.1.0"+dependencies = [+ "gloo",+ "inventory",+ "js-sys",+ "proc-macro2",+ "quote",+ "syn 2.0.117",+ "wasm-bindgen",+ "web-sys",+]++[[package]] name = "libc" version = "0.2.186" source = "registry+https://github.com/rust-lang/crates.io-index"@@ -8,7 +8,6 @@ repository = "https://github.com/johanmattssonm/kaja-web" readme = "README.md" keywords = ["html", "web", "wasm", "webassembly", "frontend"] - [dependencies] gloo = "0.12.0" gloo-console = "0.4.0"@@ -20,4 +19,5 @@ serde-wasm-bindgen = "0.5" inventory = "0.3.24" js-sys = "0.3" wasm-bindgen-futures = "0.4.72"-kaja-callback-macro = "0.1.0"+kaja-callback-macro = { path = "../kaja-callback-macro" }+kaja-web-component = { path = "../kaja-web-component" }@@ -446,9 +446,7 @@ dependencies = [ [[package]] name = "kaja-callback-macro"-version = "0.1.0"-source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "f991f9438ddafefdef1b5fb95a4a60f3bc834b419c27409d8e10a7839c47af8d"+version = "1.0.0" dependencies = [ "gloo", "proc-macro2",@@ -493,7 +491,6 @@ dependencies = [ "gloo", "inventory", "js-sys",- "kaja-callback-macro", "kaja-html-macro", "kaja-web", "serde",@@ -1083,7 +1080,3 @@ name = "zmij" version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"--[[patch.unused]]-name = "kaja-callback-macro"-version = "1.0.0"@@ -19,7 +19,6 @@ uuid = { version = "1.23.2", features = ["js", "v4"] } console_error_panic_hook = "0.1.7" inventory = "0.3.24" serde-wasm-bindgen = "0.5"-kaja-callback-macro = "0.1.0" [patch.crates-io] kaja-callback-macro = { path = "../../../kaja-callback-macro" }@@ -34,11 +34,12 @@ fn counter_disconnect(element: HtmlElement, wasm_id: u32) { } #[callback(counterInit)]-fn counter_init() {+fn counter_init() -> u32 { log!("counterInit"); let counter = Counter::default(); let mut counter_store = COUNTER_COMPONENTS.write().unwrap(); *counter_store = Some(counter);+ 42 } fn create_component(tag_name: &str) {@@ -46,19 +47,19 @@ fn create_component(tag_name: &str) { let component = Function::new_no_args( r#"- return class extends HTMLElement {- let component_id = -1;+ let componentId = -1; + return class extends HTMLElement { connectedCallback() {- if (component_id == -1) {- component_id = counter_init();+ if (componentId == -1) {+ componentId = counterInit(); } - counterComponentConnect(this, component_id);+ counterComponentConnect(this, componentId); } disconnectedCallback() {- counterComponentDisconnect(this, component_id);+ counterComponentDisconnect(this, componentId); } attributeChangedCallback(name, oldValue, newValue) {@@ -145,8 +146,8 @@ fn init_components() { pub fn init() { std::panic::set_hook(Box::new(console_error_panic_hook::hook)); console_error_panic_hook::set_once();- init_components(); init_callbacks();+ init_components(); create_component("example-component") }@@ -4,7 +4,7 @@ #![doc = include_str!("../README.md")] use gloo_console::{error, log};-use wasm_bindgen::JsCast;+use wasm_bindgen::{JsCast, JsValue}; use web_sys::{Element, HtmlDocument, HtmlElement, HtmlInputElement, NodeList}; pub mod prelude;@@ -298,3 +298,22 @@ pub fn get_callback(name: &str) -> Option<js_sys::Function> { } None }++/// HTML Component. See kaja-web-component.+pub trait Component {+ fn connected(&mut self, element: HtmlElement) {}+ fn disconnected(&mut self, element: HtmlElement) {}+ fn observed_attributes() -> &'static [&'static str] {+ &[]+ }++ fn attribute_changed(+ &mut self,+ element: HtmlElement,+ name: &str,+ old_value: &JsValue,+ new_value: &JsValue,+ ) {+ log!("Attribute changed but no update handler for ", name);+ }+}@@ -15,3 +15,6 @@ pub use wasm_bindgen_futures; pub use kaja_callback_macro::callback; pub use kaja_html_macro::html;+pub use kaja_web_component::component;++pub use js_sys::Function;