Sync ReadSignal and Store (#4608)

* Add some traits read only signal works with sync storage

* seal gats

* minimize diff
This commit is contained in:
Evan Almloff authored and GitHub committed 2025-10-03 20:05:43 -07:00
1 parent 022124e512
commit da32278b3a
4 files changed
+304 -78

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
use dioxus::prelude::*;
fn main() {
dioxus::launch(app);
}
fn app() -> Element {
let mut store = use_hook(|| Store::new_maybe_sync(0u32));
rsx! {
button { onclick: move |_| store += 1, "Increase" }
"{store}"
Child { store }
}
}
#[component]
fn Child(store: WriteStore<u32, SyncStorage>) -> Element {
// A `WriteStore<T, SyncStorage>` can be sent to another thread!
// Make sure to clean up your threads when the component unmounts.
use_hook(|| {
std::thread::spawn(move || loop {
std::thread::sleep(std::time::Duration::from_secs(1));
store += 1;
if store() >= 10 {
break;
}
});
});
rsx! {}
}