Clone in a terminal:
Commit bf5df00
Johan Mattsson - 2026-05-31T21:57:10+00:00
bf5df00ecaf7863f03ebcc19264d19fd2252fcc0johan.mattsson.m@gmail.com

Clock counter example

Changed files (12)

Diff

diff --git a/.gitignore b/.gitignoreindex ea8c4bf..45d1ce5 100644--- a/.gitignore+++ b/.gitignore@@ -1 +1,2 @@-/target+target+target/diff --git a/Cargo.lock b/Cargo.lockindex 239047d..480197e 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -30,6 +30,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"  [[package]]+name = "ctor"+version = "0.1.26"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"+dependencies = [+ "quote",+ "syn 1.0.109",+]++[[package]] name = "equivalent" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index"@@ -88,7 +98,7 @@ checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b" dependencies = [  "proc-macro2",  "quote",- "syn",+ "syn 2.0.117", ]  [[package]]@@ -134,6 +144,17 @@ dependencies = [ ]  [[package]]+name = "ghost"+version = "0.1.21"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fe3de42e89f5bd0686d0058be48d545333311e34c763f85324938ba7cc473149"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]] name = "gloo" version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index"@@ -207,7 +228,7 @@ dependencies = [  "gloo-events",  "gloo-utils 0.3.0",  "serde",- "serde-wasm-bindgen",+ "serde-wasm-bindgen 0.6.5",  "serde_urlencoded",  "thiserror 2.0.18",  "wasm-bindgen",@@ -324,7 +345,7 @@ dependencies = [  "proc-macro-crate",  "proc-macro2",  "quote",- "syn",+ "syn 2.0.117", ]  [[package]]@@ -354,6 +375,28 @@ dependencies = [ ]  [[package]]+name = "inventory"+version = "0.1.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f0eb5160c60ba1e809707918ee329adb99d222888155835c6feedba19f6c3fd4"+dependencies = [+ "ctor",+ "ghost",+ "inventory-impl",+]++[[package]]+name = "inventory-impl"+version = "0.1.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7e41b53715c6f0c4be49510bb82dee2c1e51c8586d885abe65396e82ed518548"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 1.0.109",+]++[[package]] name = "itoa" version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index"@@ -372,10 +415,26 @@ dependencies = [ ]  [[package]]+name = "kaja-callback-macro"+version = "0.1.0"+dependencies = [+ "gloo",+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]] name = "kaja-web" version = "0.1.0" dependencies = [  "gloo",+ "gloo-console",+ "inventory",+ "js-sys",+ "kaja-callback-macro",+ "serde",+ "serde-wasm-bindgen 0.5.0",  "wasm-bindgen",  "web-sys", ]@@ -421,7 +480,7 @@ checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b" dependencies = [  "proc-macro2",  "quote",- "syn",+ "syn 2.0.117", ]  [[package]]@@ -492,6 +551,17 @@ dependencies = [  [[package]] name = "serde-wasm-bindgen"+version = "0.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f3b143e2833c57ab9ad3ea280d21fd34e285a42837aeb0ee301f4f41890fa00e"+dependencies = [+ "js-sys",+ "serde",+ "wasm-bindgen",+]++[[package]]+name = "serde-wasm-bindgen" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b"@@ -518,7 +588,7 @@ checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79" dependencies = [  "proc-macro2",  "quote",- "syn",+ "syn 2.0.117", ]  [[package]]@@ -554,6 +624,17 @@ checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"  [[package]] name = "syn"+version = "1.0.109"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"+dependencies = [+ "proc-macro2",+ "quote",+ "unicode-ident",+]++[[package]]+name = "syn" version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"@@ -589,7 +670,7 @@ checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" dependencies = [  "proc-macro2",  "quote",- "syn",+ "syn 2.0.117", ]  [[package]]@@ -600,7 +681,7 @@ checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5" dependencies = [  "proc-macro2",  "quote",- "syn",+ "syn 2.0.117", ]  [[package]]@@ -674,7 +755,7 @@ dependencies = [  "bumpalo",  "proc-macro2",  "quote",- "syn",+ "syn 2.0.117",  "wasm-bindgen-shared", ] diff --git a/Cargo.toml b/Cargo.tomlindex f9bd07d..eb8ba8f 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -1,12 +1,15 @@ [package] name = "kaja-web" version = "0.1.0"-edition = "2024"+edition = "2021"  [dependencies]-gloo = { version = "0.12.0", features = ["console"] }+gloo = "0.12.0"+gloo-console = "0.4.0"+kaja-callback-macro = { version = "0.1.0", path = "../kaja-callback-macro" } wasm-bindgen = "0.2.122"--[dependencies.web-sys]-version = "0.3.91"-features = ["console", "Window", "Document", "HtmlDocument", "Element", "HtmlElement", "Node", "NodeList"]+web-sys = { version = "0.3.99", features = ["Element", "HtmlElement", "NodeList"] }+serde = { version = "1.0", features = ["derive"] }+serde-wasm-bindgen = "0.5"+inventory = "0.1"+js-sys = "0.3"diff --git a/examples/clickcounter/Cargo.lock b/examples/clickcounter/Cargo.locknew file mode 100644index 0000000..c6590f3--- /dev/null+++ b/examples/clickcounter/Cargo.lock@@ -0,0 +1,1114 @@+# This file is automatically @generated by Cargo.+# It is not intended for manual editing.+version = 4++[[package]]+name = "anyhow"+version = "1.0.102"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c"++[[package]]+name = "bincode"+version = "1.3.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad"+dependencies = [+ "serde",+]++[[package]]+name = "bitflags"+version = "2.11.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3"++[[package]]+name = "bumpalo"+version = "3.20.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"++[[package]]+name = "bytes"+version = "1.11.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1e748733b7cbc798e1434b6ac524f0c1ff2ab456fe201501e6497c8417a4fc33"++[[package]]+name = "cfg-if"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"++[[package]]+name = "console_error_panic_hook"+version = "0.1.7"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc"+dependencies = [+ "cfg-if",+ "wasm-bindgen",+]++[[package]]+name = "ctor"+version = "0.1.26"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096"+dependencies = [+ "quote",+ "syn 1.0.109",+]++[[package]]+name = "equivalent"+version = "1.0.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f"++[[package]]+name = "foldhash"+version = "0.1.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2"++[[package]]+name = "form_urlencoded"+version = "1.2.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf"+dependencies = [+ "percent-encoding",+]++[[package]]+name = "futures"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8b147ee9d1f6d097cef9ce628cd2ee62288d963e16fb287bd9286455b241382d"+dependencies = [+ "futures-channel",+ "futures-core",+ "futures-io",+ "futures-sink",+ "futures-task",+ "futures-util",+]++[[package]]+name = "futures-channel"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "07bbe89c50d7a535e539b8c17bc0b49bdb77747034daa8087407d655f3f7cc1d"+dependencies = [+ "futures-core",+ "futures-sink",+]++[[package]]+name = "futures-core"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7e3450815272ef58cec6d564423f6e755e25379b217b0bc688e295ba24df6b1d"++[[package]]+name = "futures-io"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718"++[[package]]+name = "futures-macro"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e835b70203e41293343137df5c0664546da5745f82ec9b84d40be8336958447b"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]]+name = "futures-sink"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c39754e157331b013978ec91992bde1ac089843443c49cbc7f46150b0fad0893"++[[package]]+name = "futures-task"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "037711b3d59c33004d3856fbdc83b99d4ff37a24768fa1be9ce3538a1cde4393"++[[package]]+name = "futures-util"+version = "0.3.32"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "389ca41296e6190b48053de0321d02a77f32f8a5d2461dd38762c0593805c6d6"+dependencies = [+ "futures-channel",+ "futures-core",+ "futures-io",+ "futures-macro",+ "futures-sink",+ "futures-task",+ "memchr",+ "pin-project-lite",+ "slab",+]++[[package]]+name = "getrandom"+version = "0.2.17"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"+dependencies = [+ "cfg-if",+ "js-sys",+ "libc",+ "wasi",+ "wasm-bindgen",+]++[[package]]+name = "getrandom"+version = "0.4.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555"+dependencies = [+ "cfg-if",+ "libc",+ "r-efi",+ "wasip2",+ "wasip3",+]++[[package]]+name = "ghost"+version = "0.1.21"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "fe3de42e89f5bd0686d0058be48d545333311e34c763f85324938ba7cc473149"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]]+name = "gloo"+version = "0.12.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "dc13cc21c3835347855fd83900414d94716adc1e332f09f7fba56f21be127214"+dependencies = [+ "gloo-console",+ "gloo-dialogs",+ "gloo-events",+ "gloo-file",+ "gloo-history",+ "gloo-net",+ "gloo-render",+ "gloo-storage",+ "gloo-timers",+ "gloo-utils 0.3.0",+ "gloo-worker",+]++[[package]]+name = "gloo-console"+version = "0.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9f1d5cec0b97edb53f21221f799c659cef3764ad5a00eca52950eb9b902028ba"+dependencies = [+ "gloo-utils 0.3.0",+ "js-sys",+ "serde",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-dialogs"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "45618929b7022bb49903b958b5b7af1d4fb58fbd99712926d91641fe582f3d55"+dependencies = [+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-events"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8c6a94fa8cd88bea0babf8a27fe9abbcdece831fd1c3c84dd5c231fab4685ec7"+dependencies = [+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-file"+version = "0.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "544a15ff6a3d5976bebc97380c8471ae14283bc71f4bb198d6c8cae64f411ab7"+dependencies = [+ "gloo-events",+ "js-sys",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-history"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f07f3d446931414cc92f4a1b6e631dfa233db2f96c887d5f72beeecd1b5db39c"+dependencies = [+ "getrandom 0.2.17",+ "gloo-events",+ "gloo-utils 0.3.0",+ "serde",+ "serde-wasm-bindgen 0.6.5",+ "serde_urlencoded",+ "thiserror 2.0.18",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-net"+version = "0.7.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a6420f887c48417e9e86c6cf61274eb231830cccc100e49613f7952e269a1fe1"+dependencies = [+ "futures-channel",+ "futures-core",+ "futures-sink",+ "gloo-utils 0.3.0",+ "http",+ "js-sys",+ "pin-project",+ "serde",+ "serde_json",+ "thiserror 2.0.18",+ "wasm-bindgen",+ "wasm-bindgen-futures",+ "web-sys",+]++[[package]]+name = "gloo-render"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3f609333b9e38e43e74224410d6616e3ad773ed6fe14f53cd8a006d1bb25e108"+dependencies = [+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-storage"+version = "0.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e82ce7d41c6d821640a43726f6ff33c924795cc151b62e5a84d0c988c151c980"+dependencies = [+ "gloo-utils 0.3.0",+ "js-sys",+ "serde",+ "serde_json",+ "thiserror 2.0.18",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-timers"+version = "0.4.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "482ce8a491a501da4cd806bd190275363d674f2845005c6ddbd5d3e1dd54495d"+dependencies = [+ "js-sys",+ "wasm-bindgen",+]++[[package]]+name = "gloo-utils"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0b5555354113b18c547c1d3a98fbf7fb32a9ff4f6fa112ce823a21641a0ba3aa"+dependencies = [+ "js-sys",+ "serde",+ "serde_json",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-utils"+version = "0.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4202275d95a142fa209a1e35e91c250a710c5600731372cd3464a39ed01573d6"+dependencies = [+ "js-sys",+ "serde",+ "serde_json",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "gloo-worker"+version = "0.6.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "142478655c5d764e5168d3019510ea0c0885687a72ba74e90548bd74ae160a41"+dependencies = [+ "bincode",+ "futures",+ "gloo-utils 0.2.0",+ "gloo-worker-macros",+ "js-sys",+ "pinned",+ "serde",+ "thiserror 2.0.18",+ "wasm-bindgen",+ "wasm-bindgen-futures",+ "web-sys",+]++[[package]]+name = "gloo-worker-macros"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f3bf5ede96b06406bd74351a026f708ae196b7dc262077aee56e6ad7223e7466"+dependencies = [+ "proc-macro-crate",+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]]+name = "hashbrown"+version = "0.15.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1"+dependencies = [+ "foldhash",+]++[[package]]+name = "hashbrown"+version = "0.17.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"++[[package]]+name = "heck"+version = "0.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"++[[package]]+name = "http"+version = "1.4.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8be7462df143984c4598a256ef469b251d7d7f9e271135073e78fc535414f3d0"+dependencies = [+ "bytes",+ "itoa",+]++[[package]]+name = "id-arena"+version = "2.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954"++[[package]]+name = "indexmap"+version = "2.14.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9"+dependencies = [+ "equivalent",+ "hashbrown 0.17.1",+ "serde",+ "serde_core",+]++[[package]]+name = "inventory"+version = "0.1.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f0eb5160c60ba1e809707918ee329adb99d222888155835c6feedba19f6c3fd4"+dependencies = [+ "ctor",+ "ghost",+ "inventory-impl",+]++[[package]]+name = "inventory-impl"+version = "0.1.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7e41b53715c6f0c4be49510bb82dee2c1e51c8586d885abe65396e82ed518548"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 1.0.109",+]++[[package]]+name = "itoa"+version = "1.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682"++[[package]]+name = "js-sys"+version = "0.3.99"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "142bc4740e452c1e57ade0cbc129f139c9093e354346f0872ef985f4f5cf5f11"+dependencies = [+ "cfg-if",+ "futures-util",+ "once_cell",+ "wasm-bindgen",+]++[[package]]+name = "kaja-callback-macro"+version = "0.1.0"+dependencies = [+ "gloo",+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]]+name = "kaja-html-macro"+version = "1.0.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "46133dd45e19d67a03f37f98e356c3851845cec889434a6f928c1403f6abac02"+dependencies = [+ "proc-macro-error",+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]]+name = "kaja-web"+version = "0.1.0"+dependencies = [+ "gloo",+ "gloo-console",+ "inventory",+ "js-sys",+ "kaja-callback-macro",+ "serde",+ "serde-wasm-bindgen 0.5.0",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "kaja-web-click-counter-example"+version = "0.1.0"+dependencies = [+ "console_error_panic_hook",+ "gloo",+ "js-sys",+ "kaja-callback-macro",+ "kaja-html-macro",+ "kaja-web",+ "serde",+ "serde_json",+ "uuid",+ "wasm-bindgen",+ "web-sys",+]++[[package]]+name = "leb128fmt"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"++[[package]]+name = "libc"+version = "0.2.186"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "68ab91017fe16c622486840e4c83c9a37afeff978bd239b5293d61ece587de66"++[[package]]+name = "log"+version = "0.4.30"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "616ec5685824bcc94416c6d4a7a446eea774a31efd7062c8480ba6fd06d7a6e5"++[[package]]+name = "memchr"+version = "2.8.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6b947ae49db0d222b1dbc6b113ce7248a3fc3a6ca21b696717bfc000ba4484d8"++[[package]]+name = "once_cell"+version = "1.21.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"++[[package]]+name = "percent-encoding"+version = "2.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220"++[[package]]+name = "pin-project"+version = "1.1.13"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2466b2336ed02bcdca6b294417127b90ec92038d1d5c4fbeac971a922e0e0924"+dependencies = [+ "pin-project-internal",+]++[[package]]+name = "pin-project-internal"+version = "1.1.13"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "c96395f0a926bc13b1c17622aaddda1ecb55d49c8f1bf9777e4d877800a43f8b"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]]+name = "pin-project-lite"+version = "0.2.17"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd"++[[package]]+name = "pinned"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a829027bd95e54cfe13e3e258a1ae7b645960553fb82b75ff852c29688ee595b"+dependencies = [+ "futures",+ "rustversion",+ "thiserror 1.0.69",+]++[[package]]+name = "prettyplease"+version = "0.2.37"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b"+dependencies = [+ "proc-macro2",+ "syn 2.0.117",+]++[[package]]+name = "proc-macro-crate"+version = "3.3.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "edce586971a4dfaa28950c6f18ed55e0406c1ab88bbce2c6f6293a7aaba73d35"+dependencies = [+ "toml_edit",+]++[[package]]+name = "proc-macro-error"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"+dependencies = [+ "proc-macro-error-attr",+ "proc-macro2",+ "quote",+ "syn 1.0.109",+ "version_check",+]++[[package]]+name = "proc-macro-error-attr"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"+dependencies = [+ "proc-macro2",+ "quote",+ "version_check",+]++[[package]]+name = "proc-macro2"+version = "1.0.106"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"+dependencies = [+ "unicode-ident",+]++[[package]]+name = "quote"+version = "1.0.45"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"+dependencies = [+ "proc-macro2",+]++[[package]]+name = "r-efi"+version = "6.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"++[[package]]+name = "rustversion"+version = "1.0.22"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"++[[package]]+name = "ryu"+version = "1.0.23"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f"++[[package]]+name = "semver"+version = "1.0.28"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd"++[[package]]+name = "serde"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9a8e94ea7f378bd32cbbd37198a4a91436180c5bb472411e48b5ec2e2124ae9e"+dependencies = [+ "serde_core",+ "serde_derive",+]++[[package]]+name = "serde-wasm-bindgen"+version = "0.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f3b143e2833c57ab9ad3ea280d21fd34e285a42837aeb0ee301f4f41890fa00e"+dependencies = [+ "js-sys",+ "serde",+ "wasm-bindgen",+]++[[package]]+name = "serde-wasm-bindgen"+version = "0.6.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8302e169f0eddcc139c70f139d19d6467353af16f9fce27e8c30158036a1e16b"+dependencies = [+ "js-sys",+ "serde",+ "wasm-bindgen",+]++[[package]]+name = "serde_core"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "41d385c7d4ca58e59fc732af25c3983b67ac852c1a25000afe1175de458b67ad"+dependencies = [+ "serde_derive",+]++[[package]]+name = "serde_derive"+version = "1.0.228"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d540f220d3187173da220f885ab66608367b6574e925011a9353e4badda91d79"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]]+name = "serde_json"+version = "1.0.150"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9"+dependencies = [+ "itoa",+ "memchr",+ "serde",+ "serde_core",+ "zmij",+]++[[package]]+name = "serde_urlencoded"+version = "0.7.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"+dependencies = [+ "form_urlencoded",+ "itoa",+ "ryu",+ "serde",+]++[[package]]+name = "slab"+version = "0.4.12"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5"++[[package]]+name = "syn"+version = "1.0.109"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237"+dependencies = [+ "proc-macro2",+ "quote",+ "unicode-ident",+]++[[package]]+name = "syn"+version = "2.0.117"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"+dependencies = [+ "proc-macro2",+ "quote",+ "unicode-ident",+]++[[package]]+name = "thiserror"+version = "1.0.69"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"+dependencies = [+ "thiserror-impl 1.0.69",+]++[[package]]+name = "thiserror"+version = "2.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4288b5bcbc7920c07a1149a35cf9590a2aa808e0bc1eafaade0b80947865fbc4"+dependencies = [+ "thiserror-impl 2.0.18",+]++[[package]]+name = "thiserror-impl"+version = "1.0.69"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]]+name = "thiserror-impl"+version = "2.0.18"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ebc4ee7f67670e9b64d05fa4253e753e016c6c95ff35b89b7941d6b856dec1d5"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 2.0.117",+]++[[package]]+name = "toml_datetime"+version = "0.6.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c"++[[package]]+name = "toml_edit"+version = "0.22.27"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "41fe8c660ae4257887cf66394862d21dbca4a6ddd26f04a3560410406a2f819a"+dependencies = [+ "indexmap",+ "toml_datetime",+ "winnow",+]++[[package]]+name = "unicode-ident"+version = "1.0.24"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"++[[package]]+name = "unicode-xid"+version = "0.2.6"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853"++[[package]]+name = "uuid"+version = "1.23.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d258b83ceec21034727ecee8c382cfa6c3e133699b0742c64571814fb420c9f7"+dependencies = [+ "getrandom 0.4.2",+ "js-sys",+ "wasm-bindgen",+]++[[package]]+name = "version_check"+version = "0.9.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"++[[package]]+name = "wasi"+version = "0.11.1+wasi-snapshot-preview1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"++[[package]]+name = "wasip2"+version = "1.0.3+wasi-0.2.9"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6"+dependencies = [+ "wit-bindgen 0.57.1",+]++[[package]]+name = "wasip3"+version = "0.4.0+wasi-0.3.0-rc-2026-01-06"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5"+dependencies = [+ "wit-bindgen 0.51.0",+]++[[package]]+name = "wasm-bindgen"+version = "0.2.122"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3ed04576f974d2b2fba0f38c51dbc5518011e38c36bf1143164be765528fd409"+dependencies = [+ "cfg-if",+ "once_cell",+ "rustversion",+ "wasm-bindgen-macro",+ "wasm-bindgen-shared",+]++[[package]]+name = "wasm-bindgen-futures"+version = "0.4.72"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9473dbd2991ae90b6291c3c32c30c6187ac49aa32f9905d1cce280ec1e110b0f"+dependencies = [+ "js-sys",+ "wasm-bindgen",+]++[[package]]+name = "wasm-bindgen-macro"+version = "0.2.122"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "916151b09da36bd82f6615cbf3a419e2f0ba23a03c6160e8e92eb6bd4aa1dec6"+dependencies = [+ "quote",+ "wasm-bindgen-macro-support",+]++[[package]]+name = "wasm-bindgen-macro-support"+version = "0.2.122"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "299047362ccbfce148b67ab7e73349f77748e00c8296f9542adfad2ad82c5c5e"+dependencies = [+ "bumpalo",+ "proc-macro2",+ "quote",+ "syn 2.0.117",+ "wasm-bindgen-shared",+]++[[package]]+name = "wasm-bindgen-shared"+version = "0.2.122"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9a929b2c61f11ba3e9bc35b50c1f25cb38e0e892c0c231ae2b8cf78d5dad4437"+dependencies = [+ "unicode-ident",+]++[[package]]+name = "wasm-encoder"+version = "0.244.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319"+dependencies = [+ "leb128fmt",+ "wasmparser",+]++[[package]]+name = "wasm-metadata"+version = "0.244.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909"+dependencies = [+ "anyhow",+ "indexmap",+ "wasm-encoder",+ "wasmparser",+]++[[package]]+name = "wasmparser"+version = "0.244.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe"+dependencies = [+ "bitflags",+ "hashbrown 0.15.5",+ "indexmap",+ "semver",+]++[[package]]+name = "web-sys"+version = "0.3.99"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "6d621441cfc37b84979402712047321980c178f299193a3589d05b99e8763436"+dependencies = [+ "js-sys",+ "wasm-bindgen",+]++[[package]]+name = "winnow"+version = "0.7.15"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "df79d97927682d2fd8adb29682d1140b343be4ac0f08fd68b7765d9c059d3945"+dependencies = [+ "memchr",+]++[[package]]+name = "wit-bindgen"+version = "0.51.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5"+dependencies = [+ "wit-bindgen-rust-macro",+]++[[package]]+name = "wit-bindgen"+version = "0.57.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e"++[[package]]+name = "wit-bindgen-core"+version = "0.51.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc"+dependencies = [+ "anyhow",+ "heck",+ "wit-parser",+]++[[package]]+name = "wit-bindgen-rust"+version = "0.51.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21"+dependencies = [+ "anyhow",+ "heck",+ "indexmap",+ "prettyplease",+ "syn 2.0.117",+ "wasm-metadata",+ "wit-bindgen-core",+ "wit-component",+]++[[package]]+name = "wit-bindgen-rust-macro"+version = "0.51.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a"+dependencies = [+ "anyhow",+ "prettyplease",+ "proc-macro2",+ "quote",+ "syn 2.0.117",+ "wit-bindgen-core",+ "wit-bindgen-rust",+]++[[package]]+name = "wit-component"+version = "0.244.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2"+dependencies = [+ "anyhow",+ "bitflags",+ "indexmap",+ "log",+ "serde",+ "serde_derive",+ "serde_json",+ "wasm-encoder",+ "wasm-metadata",+ "wasmparser",+ "wit-parser",+]++[[package]]+name = "wit-parser"+version = "0.244.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736"+dependencies = [+ "anyhow",+ "id-arena",+ "indexmap",+ "log",+ "semver",+ "serde",+ "serde_derive",+ "serde_json",+ "unicode-xid",+ "wasmparser",+]++[[package]]+name = "zmij"+version = "1.0.21"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa"diff --git a/examples/clickcounter/Cargo.toml b/examples/clickcounter/Cargo.tomlnew file mode 100644index 0000000..3cc23a2--- /dev/null+++ b/examples/clickcounter/Cargo.toml@@ -0,0 +1,24 @@+[package]+name = "kaja-web-click-counter-example"+version = "0.1.0"+edition = "2024"++[lib]+crate-type = ["cdylib"]++[dependencies]+wasm-bindgen = "0.2.122"+kaja-web = { path = "../.." }++# No inventory/ctor/callback-macro on wasm example: exports use wasm_bindgen directly+js-sys = "0.3"+web-sys = { version = "0.3.99", features = ["Element", "HtmlElement", "NodeList"] }++gloo = "0.12"+kaja-html-macro = "1.0.3"+serde = { version = "1.0.228", features = ["derive"] }+serde_json = "1.0.150"+# Ensure uuid has a wasm-compatible RNG source (uses Web Crypto via `js` feature)+uuid = { version = "1.23.2", features = ["js", "v4"] }+console_error_panic_hook = "0.1.7"+kaja-callback-macro = { version = "0.1.0", path = "../../../kaja-callback-macro" }diff --git a/examples/clickcounter/build.sh b/examples/clickcounter/build.shnew file mode 100755index 0000000..190835d--- /dev/null+++ b/examples/clickcounter/build.sh@@ -0,0 +1,15 @@+#!/bin/sh++set -e+cargo build++wasm-pack build \+    --release \+    --target web \+    --out-dir pkg \+    --out-name clickcounter \+    --no-typescript++cp index.html pkg/+cp main.js pkg/+cp styles.css pkg/diff --git a/examples/clickcounter/index.html b/examples/clickcounter/index.htmlnew file mode 100644index 0000000..f8327e2--- /dev/null+++ b/examples/clickcounter/index.html@@ -0,0 +1,14 @@+<!doctype html>+<html lang="en">+    <head>+        <meta charset="UTF-8" />+        <link rel="stylesheet" href="styles.css" />+        <meta name="viewport" content="width=device-width, initial-scale=1.0" />+        <title>Example: Click Counter</title>+        <script type="module" src="main.js" defer></script>+    </head>++    <body>+        <main id="click-counter"></main>+    </body>+</html>diff --git a/examples/clickcounter/main.js b/examples/clickcounter/main.jsnew file mode 100644index 0000000..827c95a--- /dev/null+++ b/examples/clickcounter/main.js@@ -0,0 +1,26 @@+let wasmModule;++async function loadWasm() {+  try {+    const wasmModule = await import("./clickcounter.js");+    await wasmModule.default("./clickcounter_bg.wasm");+    await wasmModule.initCallbacks();+    return wasmModule;+  } catch (error) {+    console.error("Failed to load WASM module:", error);+    return null;+  }+}++window.addEventListener("DOMContentLoaded", async () => {+  wasmModule = await loadWasm();++  window.realjs = function () {+    console.log("RealJS");++    wasmModule.test();+    //wasmModule.incrementCounter();+  };++  window.runTest = wasmModule.test;+});diff --git a/examples/clickcounter/run.sh b/examples/clickcounter/run.shnew file mode 100755index 0000000..a048608--- /dev/null+++ b/examples/clickcounter/run.sh@@ -0,0 +1,7 @@+#!/bin/bash+set -e++./build.sh++cd pkg+python3 -m http.server 8080 --bind 127.0.0.1diff --git a/examples/clickcounter/src/lib.rs b/examples/clickcounter/src/lib.rsnew file mode 100644index 0000000..3507988--- /dev/null+++ b/examples/clickcounter/src/lib.rs@@ -0,0 +1,73 @@+#![cfg(target_arch = "wasm32")]+use gloo::console::log;+use kaja_callback_macro::callback;+use kaja_html_macro::html;+use kaja_web::*;+use std::sync::RwLock;+use wasm_bindgen::prelude::*;++struct AppData {+    current_count: usize,+}++pub static APP_DATA: RwLock<AppData> = RwLock::new(AppData { current_count: 0 });++#[callback("incrementCounter")]+pub fn increment_counter() {+    let mut app_data = APP_DATA.write().unwrap();+    app_data.current_count = app_data.current_count.saturating_add(1);+    update_counter_display(&app_data);+}++#[callback("decrementCounter")]+pub fn decrement_counter() {+    let mut app_data = APP_DATA.write().unwrap();+    app_data.current_count = app_data.current_count.saturating_sub(1);+    update_counter_display(&app_data);+}++#[wasm_bindgen(js_name = initCallbacks)]+pub fn init_callbacks() {+    log!("Initializing callbacks");+    increment_counter_register();+    decrement_counter_register();+}++fn update_counter_display(app_data: &AppData) {+    log!("Updating counter display");+    let count = app_data.current_count;++    log!("Updating counter display: count = {}", count);++    let counter = html! {{+        <div class="click-counter-display">$count</div>++        <button class="click-counter-increment-button"+            onclick="incrementCounter()"+        >+            Increment+        </button>++        <button class="click-counter-decrement-button"+            onclick="decrementCounter()"+        >+            Decrement+        </button>+    }};++    let result = inner_html("#click-counter", counter.as_str());++    if result.is_err() {+        log!("Failed to set inner HTML for '#click-counter'.");+    }+}++#[wasm_bindgen(start)]+pub fn init() {+    std::panic::set_hook(Box::new(console_error_panic_hook::hook));++    let mut app_data = APP_DATA.read().unwrap();+    update_counter_display(&app_data);++    init_callbacks();+}diff --git a/examples/clickcounter/styles.css b/examples/clickcounter/styles.cssnew file mode 100644index 0000000..c24badf--- /dev/null+++ b/examples/clickcounter/styles.css@@ -0,0 +1,50 @@+:root {+    font-family: Inter, Avenir, Helvetica, Arial, sans-serif;+    font-size: 16px;+    line-height: 24px;+    font-weight: 400;++    color: #0f0f0f;+    background-color: #f6f6f6;+}++input,+button {+    border-radius: 8px;+    border: 1px solid transparent;+    padding: 0.6em 1.2em;+    font-size: 1em;+    font-weight: 500;+    font-family: inherit;+    color: #0f0f0f;+    background-color: #ffffff;+    transition: border-color 0.25s;+    box-shadow: 0 2px 2px rgba(0, 0, 0, 0.2);+    padding-bottom: 7px;+    margin-bottom: 10px;+}++button {+    cursor: pointer;+}++input,+button {+    outline: none;+}++@media (prefers-color-scheme: dark) {+    :root {+        color: #f6f6f6;+        background-color: #2f2f2f;+    }++    input,+    button {+        color: #ffffff;+        background-color: #0f0f0f98;+    }+    button:active {+        background-color: #0f0f0f69;+    }+}diff --git a/src/lib.rs b/src/lib.rsindex 819acf7..87a9df9 100644--- a/src/lib.rs+++ b/src/lib.rs@@ -7,6 +7,33 @@ pub struct Error;  type Result<T> = std::result::Result<T, Error>; +pub struct JsCallItem {+    pub name: &'static str,+    pub install: fn(),+}++pub struct App {}++pub struct CallbackRegistration {+    pub register: fn(),+}++unsafe impl Sync for CallbackRegistration {}++inventory::collect!(CallbackRegistration);++impl App {+    pub fn new() -> Self {+        App {}+    }++    pub fn set_callbacks(&self) {+        for reg in inventory::iter::<CallbackRegistration> {+            (reg.register)();+        }+    }+}+ /// Queries the document for a single element matching the given selector. /// Returns `None` if no element is found. Returns first matching element if multiple are found. pub fn get_element(selector: &str) -> Option<HtmlElement> {@@ -68,7 +95,7 @@ pub fn get_elements(selector: &str) -> Vec<HtmlElement> {     return node_list_to_vec(elements.unwrap()); } -/// Sets the inner HTML of the first element matching the given selector.+/// Sets the inner HTML of the elements matching the given selector. /// Returns an error if no element is found. pub fn inner_html(selector: &str, html: &str) -> Result<()> {     let window = web_sys::window().ok_or(Error)?;@@ -91,7 +118,7 @@ pub fn inner_html(selector: &str, html: &str) -> Result<()> {     Ok(()) } -/// Sets the inner text of the first element matching the given selector.+/// Sets the inner text of the elements matching the given selector. /// Returns an error if no element is found. pub fn inner_text(selector: &str, text: &str) -> Result<()> {     let window = web_sys::window().ok_or(Error)?;@@ -123,3 +150,53 @@ pub fn try_inner_html(selector: &str, html: &str) { pub fn try_inner_text(selector: &str, text: &str) {     let _ = inner_text(selector, text); }++#[macro_export]+macro_rules! callback {+    ($js_name:ident, $rust_fn:path) => {{+        use wasm_bindgen::closure::Closure;+        use wasm_bindgen::JsCast;+        use wasm_bindgen::JsValue;++        let window = web_sys::window().unwrap();++        let cb = Closure::<dyn FnMut(JsValue)>::new(|val: JsValue| {+            let event: _ =+                serde_wasm_bindgen::from_value(val).expect("Failed to deserialize event");++            $rust_fn(event);+        });++        ::js_sys::Reflect::set(+            &window,+            &stringify!($js_name).into(),+            cb.as_ref().unchecked_ref(),+        )+        .unwrap();++        cb.forget();+    }};+}++#[cfg(all(test, target_arch = "wasm32"))]+mod tests {+    use crate::App;+    use crate::CallbackRegistration;+    use gloo_console::log;+    use js_sys;+    #[derive(Debug, serde::Deserialize)]+    struct SomeClickEvent {+        índex: usize,+    }++    #[kaja_callback_macro::callback("someClickCallback")]+    fn some_on_click_function(event: SomeClickEvent) {+        log!("event.índex: {:?}", event.índex);+    }++    #[test]+    fn test_compile() {+        let app = App::new();+        app.set_callbacks(); // 👈 registers ALL #[callback] functions automatically+    }+}

Contact

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