fix subscriptions in events

This commit is contained in:
Evan Almloff committed 2023-08-04 17:23:57 -07:00
1 parent 07ed3e67dd
commit a6f611eccf
12 files changed
+445 -103

No files matched your search

+48 -14
View File
@@ -1,26 +1,60 @@
//! Example: README.md showcase
//!
//! The example from the README.md.
#![allow(non_snake_case)]
use dioxus::prelude::*;
use dioxus_signals::use_signal;
use dioxus_signals::{use_signal, Effect, Signal};
fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let mut count = use_signal(cx, || 0);
let counts = use_signal(cx, || (0..100).map(Signal::new).collect::<Vec<_>>());
use_future!(cx, || async move {
loop {
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
count += 1;
println!("current: {count}");
}
cx.use_hook(|| {
Effect::new(move || {
println!("Counts: {:?}", counts);
})
});
cx.render(rsx! {
div { "High-Five counter: {count}" }
})
render! {
for count in counts {
Child {
count: count,
}
}
}
}
#[derive(Props, PartialEq)]
struct ChildProps {
count: Signal<u64>,
}
fn Child(cx: Scope<ChildProps>) -> Element {
let count = cx.props.count;
// use_future!(cx, || async move {
// loop {
// tokio::time::sleep(std::time::Duration::from_secs(count.value())).await;
// *count.write() += 1;
// }
// });
render! {
div {
"Child: {count}"
button {
onclick: move |_| {
*count.write() += 1;
},
"Increase"
}
button {
onclick: move |_| {
*count.write() -= 1;
},
"Decrease"
}
}
}
}