Commit 234866d
Make async functions work as callbacks
Changed files (7)
modifiedCargo.lockmodifiedCargo.tomlmodifiedexamples/callbacks/Cargo.lockmodifiedexamples/callbacks/Cargo.tomlmodifiedexamples/callbacks/src/lib.rsmodifiedexamples/clickcounter/src/lib.rsmodifiedsrc/prelude.rs
Diff
@@ -415,6 +415,7 @@ dependencies = [ "serde", "serde-wasm-bindgen 0.5.0", "wasm-bindgen",+ "wasm-bindgen-futures", "web-sys", ] @@ -14,3 +14,4 @@ serde = { version = "1.0", features = ["derive"] } serde-wasm-bindgen = "0.5" inventory = "0.3.24" js-sys = "0.3"+wasm-bindgen-futures = "0.4.72"@@ -479,6 +479,7 @@ dependencies = [ "serde", "serde-wasm-bindgen 0.5.0", "wasm-bindgen",+ "wasm-bindgen-futures", "web-sys", ] @@ -498,6 +499,7 @@ dependencies = [ "serde_json", "uuid", "wasm-bindgen",+ "wasm-bindgen-futures", "web-sys", ] @@ -21,3 +21,4 @@ console_error_panic_hook = "0.1.7" kaja-callback-macro = { version = "0.1.0", path = "../../../kaja-callback-macro" } inventory = "0.3.24" serde-wasm-bindgen = "0.5"+wasm-bindgen-futures = "0.4.72"@@ -16,13 +16,17 @@ fn update() { Test 1 </button> - <button onclick="test2({test_parameter: 'just a test'}, 'string_param'">+ <button onclick="test2({test_parameter: 'just a test'}, 'string_param');"> Test 2 </button> <button onclick="test3(1, 2, 3)"> Test 3 </button>++ <button onclick="asyncTest('run later');">+ Test Async+ </button> }}; let result = inner_html("#main-view", counter.as_str());@@ -68,6 +72,12 @@ pub fn test3(a: u32, b: u32, c: u32) { set_color("pink"); } +#[callback(asyncTest)]+async fn async_test(message: String) {+ log!("Async?: ", &message);+ set_color("black");+}+ #[wasm_bindgen(start)] pub fn init() { std::panic::set_hook(Box::new(console_error_panic_hook::hook));@@ -1,4 +1,3 @@-#![cfg(target_arch = "wasm32")] use kaja_web::prelude::*; use std::sync::RwLock; @@ -10,6 +10,7 @@ pub use serde_wasm_bindgen; pub use wasm_bindgen::prelude::wasm_bindgen; pub use wasm_bindgen::JsCast; pub use wasm_bindgen::JsValue;+pub use wasm_bindgen_futures; pub use kaja_callback_macro::callback; pub use kaja_html_macro::html;