2023-08-08 20:06:33 +00:00
|
|
|
#![allow(non_snake_case)]
|
|
|
|
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
use dioxus_signals::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
dioxus_desktop::launch(app);
|
|
|
|
}
|
|
|
|
|
2024-01-14 04:51:37 +00:00
|
|
|
fn app() -> Element {
|
|
|
|
let signal = use_signal(|| 0);
|
2023-08-08 20:06:33 +00:00
|
|
|
|
2024-01-14 05:12:21 +00:00
|
|
|
use_future(|| async move {
|
2023-08-08 20:06:33 +00:00
|
|
|
loop {
|
|
|
|
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
|
|
|
|
*signal.write() += 1;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-01-14 05:12:21 +00:00
|
|
|
let local_state = use_signal(|| 0);
|
2024-01-14 04:51:37 +00:00
|
|
|
let computed = use_selector_with_dependencies((local_state.get(),), move |(local_state,)| {
|
|
|
|
local_state * 2 + signal.value()
|
|
|
|
});
|
2023-08-08 20:06:33 +00:00
|
|
|
println!("Running app");
|
|
|
|
|
|
|
|
render! {
|
|
|
|
button {
|
|
|
|
onclick: move |_| {
|
|
|
|
local_state.set(local_state.get() + 1);
|
|
|
|
},
|
|
|
|
"Add one"
|
|
|
|
}
|
|
|
|
div {
|
|
|
|
"{computed}"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|