2023-12-16 00:35:48 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
2024-01-19 22:19:49 +00:00
|
|
|
// dioxus_desktop::launch(app);
|
2023-12-16 00:35:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
enum ErrorComponent {
|
2023-12-17 23:55:02 +00:00
|
|
|
Read,
|
|
|
|
ReadMut,
|
|
|
|
ReadDropped,
|
2023-12-16 00:35:48 +00:00
|
|
|
}
|
|
|
|
|
2024-01-19 22:19:49 +00:00
|
|
|
fn app() -> Element {
|
|
|
|
let mut error = use_signal(|| None as Option<ErrorComponent>);
|
2023-12-16 00:35:48 +00:00
|
|
|
|
|
|
|
render! {
|
2024-01-19 22:19:49 +00:00
|
|
|
match error() {
|
2023-12-17 23:55:02 +00:00
|
|
|
Some(ErrorComponent::Read) => render! { Read {} },
|
|
|
|
Some(ErrorComponent::ReadMut) => render! { ReadMut {} },
|
|
|
|
Some(ErrorComponent::ReadDropped) => render! { ReadDropped {} },
|
2023-12-16 00:35:48 +00:00
|
|
|
None => render! {
|
2024-01-19 22:19:49 +00:00
|
|
|
button { onclick: move |_| error.set(Some(ErrorComponent::Read)), "Read" }
|
|
|
|
button { onclick: move |_| error.set(Some(ErrorComponent::ReadMut)), "ReadMut" }
|
|
|
|
button { onclick: move |_| error.set(Some(ErrorComponent::ReadDropped)), "ReadDropped"}
|
2023-12-16 00:35:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-19 22:19:49 +00:00
|
|
|
#[component]
|
|
|
|
fn Read() -> Element {
|
|
|
|
let mut signal = use_signal_sync(|| 0);
|
2023-12-16 00:35:48 +00:00
|
|
|
|
|
|
|
let _write = signal.write();
|
|
|
|
let _read = signal.read();
|
|
|
|
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-01-19 22:19:49 +00:00
|
|
|
#[component]
|
|
|
|
fn ReadMut() -> Element {
|
|
|
|
let mut signal = use_signal_sync(|| 0);
|
2023-12-16 00:35:48 +00:00
|
|
|
|
|
|
|
let _read = signal.read();
|
|
|
|
let _write = signal.write();
|
|
|
|
|
|
|
|
todo!()
|
|
|
|
}
|
|
|
|
|
2024-01-19 22:19:49 +00:00
|
|
|
#[component]
|
|
|
|
fn ReadDropped() -> Element {
|
|
|
|
let signal = use_signal_sync(|| None as Option<SyncSignal<i32>>);
|
|
|
|
|
|
|
|
if generation() < 4 {
|
|
|
|
needs_update();
|
2023-12-16 00:35:48 +00:00
|
|
|
}
|
2024-01-19 22:19:49 +00:00
|
|
|
|
2023-12-16 00:35:48 +00:00
|
|
|
render! {
|
2024-01-19 22:19:49 +00:00
|
|
|
if let Some(value) = signal() {
|
|
|
|
"{value:?}"
|
2023-12-16 00:35:48 +00:00
|
|
|
} else {
|
2024-01-19 22:19:49 +00:00
|
|
|
ReadDroppedSignalChild { parent_signal: signal }
|
2023-12-16 00:35:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[component]
|
2024-01-19 22:19:49 +00:00
|
|
|
fn ReadDroppedSignalChild(parent_signal: SyncSignal<Option<SyncSignal<i32>>>) -> Element {
|
|
|
|
let signal = use_signal_sync(|| 0);
|
|
|
|
|
|
|
|
use_hook(move || parent_signal.set(Some(signal)));
|
|
|
|
|
|
|
|
render! { "{signal}" }
|
2023-12-16 00:35:48 +00:00
|
|
|
}
|