Clone in a terminal:
Commit 6b30cee
Johan Mattsson - 2026-06-29T16:27:27+00:00
6b30ceeb75aa1244b25d4df85c29d77be55e86d9johan.mattsson.m@gmail.com

Callback updated

Changed files (4)

Diff

diff --git a/examples/counter-component/src/counter.rs b/examples/counter-component/src/counter.rsindex 2f9f0c8..4672a79 100644--- a/examples/counter-component/src/counter.rs+++ b/examples/counter-component/src/counter.rs@@ -15,7 +15,6 @@ impl Component for Counter {     }      fn observed_attributes() -> &'static [&'static str] {-        log!("fetching observed attributes");         &["count"]     } @@ -26,7 +25,6 @@ impl Component for Counter {         old_value: &str,         new_value: &str,     ) {-        log!("change", name, "from", old_value, "to", new_value);         self.render(&element);     } }@@ -62,8 +60,6 @@ impl Counter {  #[callback(increment)] pub fn increment(id: String) {-    log!("increment");-     let element = get_component_element(id.as_str());      if element.is_none() {@@ -86,7 +82,7 @@ pub fn increment(id: String) {     let new_count = count + 1;      if let Some(counter_arc) = get_component::<Counter>(id.as_str()) {-        let mut counter = counter_arc.write().unwrap();+        let mut counter = counter_arc.lock().unwrap();         counter.value = new_count;         counter.render(&html_element);     } else {diff --git a/examples/counter-component/src/lib.rs b/examples/counter-component/src/lib.rsindex d6ff4ee..f036776 100644--- a/examples/counter-component/src/lib.rs+++ b/examples/counter-component/src/lib.rs@@ -1,10 +1,10 @@ use kaja_web::prelude::*;  mod counter;-mod main;+mod main_component;  use counter::*;-use main::*;+use main_component::*;  #[wasm_bindgen(start)] pub fn init() {diff --git a/examples/counter-component/src/main.rs b/examples/counter-component/src/main.rsdeleted file mode 100644index 9d86310..0000000--- a/examples/counter-component/src/main.rs+++ /dev/null@@ -1,23 +0,0 @@-use kaja_web::prelude::*;--#[component("main-component")]-pub struct Main {-    message: Option<String>,-}--impl Component for Main {-    fn connected(&mut self, element: HtmlElement) {-        self.render(element);-    }-}--impl Main {-    fn render(&self, element: HtmlElement) {-        let content = html! {{-            <div><counter-component count="1" /></div>-            <div><counter-component count="42" /></div>-        }};--        element.set_inner_html(content.as_str());-    }-}diff --git a/src/lib.rs b/src/lib.rsindex e649256..7ee63d7 100644--- a/src/lib.rs+++ b/src/lib.rs@@ -25,6 +25,14 @@ pub static NEXT_COMPONENT_COUNTER: std::sync::atomic::AtomicU32 = #[derive(Debug, Clone, Copy)] pub struct Error; +impl std::fmt::Display for Error {+    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+        write!(f, "kaja_web::Error")+    }+}++impl std::error::Error for Error {}+ pub type Result<T> = std::result::Result<T, Error>;  pub struct CallbackRegistration {@@ -60,17 +68,11 @@ inventory::collect!(CallbackRegistration); /// }}; /// ``` pub fn init_callbacks() {-    log!("init_callbacks");--    log!("init_callbacks functions");     for init in inventory::iter::<InitFn> {-        log!("init fn");         (init.0)();     } -    log!("init_callbacks components");     for init in inventory::iter::<InitComponentFn> {-        log!("init component");         (init.0)();     } }@@ -346,14 +348,14 @@ pub fn get_component_element(id: &str) -> Option<HtmlElement> { }  pub trait ComponentStorage: Sized {-    fn storage() -> &'static RwLock<Option<HashMap<String, std::sync::Arc<std::sync::RwLock<Self>>>>>;+    fn storage() -> &'static RwLock<Option<HashMap<String, std::sync::Arc<std::sync::Mutex<Self>>>>>; }  /// Returns a cloned Arc pointing to the stored component. The component itself is /// protected by an `RwLock` so callers can lock it for mutable or shared access when needed. pub fn get_component<T: ComponentStorage + 'static>(     id: &str,-) -> Option<std::sync::Arc<std::sync::RwLock<T>>> {+) -> Option<std::sync::Arc<std::sync::Mutex<T>>> {     let map_lock = T::storage().read();      if map_lock.is_err() {

Contact

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