Clone in a terminal:
main_component.rs
use kaja_web::prelude::*; #[component("main-component")] struct Main { #[attribute] test: bool, } impl Component for MainComponent { fn connected(&self) { log!("Connected:", self.get_id()); } fn disconnected(&self) { log!("Disconnected:", self.get_id()); } fn attribute_changed(&self, name: &str, _old_value: &str, _new_value: &str) { if name == "test" { self.render(); } } } impl MainComponent { fn render(&self) { let test: bool = self.get_attribute("test").unwrap_or_default(); let content = html! {{ <p>Test: $test</p> }}; let id = self.get_id(); if let Some(element) = get_element_by_id(&id) { element.set_inner_html(content.as_str()); } else { error!("Element not found for component id:", id); } } } pub(crate) fn start_background_task() { wasm_bindgen_futures::spawn_local(async move { loop { let elements = get_elements("main-component"); for element in elements { let id = element.id(); if id.is_empty() { continue; } if let Some(element) = get_element_by_id(&id) { let test = element .get_attribute("test") .unwrap_or_default() .parse::<bool>() .unwrap_or_default(); let test = !test; let _ = element.set_attribute("test", test.to_string().as_str()); } else { error!("Element not found for component id:", id); } } gloo_timers::future::TimeoutFuture::new(1000).await; } }); }

File history (10 commits)

e5c0d89 Johan Mattsson - johan.mattsson.m@gmail.com
NPM package
NPM package
ae58226 Johan Mattsson - johan.mattsson.m@gmail.com
Update example
Update example
4b41cda Johan Mattsson - johan.mattsson.m@gmail.com
Attribute tests
Attribute tests
6136236 Johan Mattsson - johan.mattsson.m@gmail.com
Tests and examples
Tests and examples
321ec6b Johan Mattsson - johan.mattsson.m@gmail.com
Remove threads with shared memory
Remove threads with shared memory
45ddf9d Johan Mattsson - johan.mattsson.m@gmail.com
ArcSwap instead of lock
ArcSwap instead of lock
2759560 Johan Mattsson - johan.mattsson.m@gmail.com
Multiple wasm threads
Multiple wasm threads
cfe5d0c Johan Mattsson - johan.mattsson.m@gmail.com
Update component code
Update component code
8def408 Johan Mattsson - johan.mattsson.m@gmail.com
New example component
New example component
06a68b2 Johan Mattsson - johan.mattsson.m@gmail.com
Try multi thread component ideas
Try multi thread component ideas

Contact

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