2023-12-16 00:35:48 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
2024-01-31 01:59:57 +00:00
|
|
|
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
|
|
|
|
2024-01-31 01:59:57 +00:00
|
|
|
rsx! {
|
2024-01-19 22:19:49 +00:00
|
|
|
match error() {
|
2024-01-31 01:59:57 +00:00
|
|
|
Some(ErrorComponent::Read) => rsx! { Read {} },
|
|
|
|
Some(ErrorComponent::ReadMut) => rsx! { ReadMut {} },
|
|
|
|
Some(ErrorComponent::ReadDropped) => rsx! { ReadDropped {} },
|
|
|
|
None => rsx! {
|
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 {
|
2024-03-08 16:46:34 +00:00
|
|
|
let signal = use_signal_sync(|| 0);
|
2023-12-16 00:35:48 +00:00
|
|
|
|
2024-03-08 16:46:34 +00:00
|
|
|
let _write = signal.write_unchecked();
|
2023-12-16 00:35:48 +00:00
|
|
|
let _read = signal.read();
|
|
|
|
|
2024-02-01 00:26:12 +00:00
|
|
|
unreachable!()
|
2023-12-16 00:35:48 +00:00
|
|
|
}
|
|
|
|
|
2024-01-19 22:19:49 +00:00
|
|
|
#[component]
|
|
|
|
fn ReadMut() -> Element {
|
2024-03-08 16:46:34 +00:00
|
|
|
let signal = use_signal_sync(|| 0);
|
2023-12-16 00:35:48 +00:00
|
|
|
|
|
|
|
let _read = signal.read();
|
2024-03-08 16:46:34 +00:00
|
|
|
let _write = signal.write_unchecked();
|
2023-12-16 00:35:48 +00:00
|
|
|
|
2024-02-01 00:26:12 +00:00
|
|
|
unreachable!()
|
2023-12-16 00:35:48 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2024-01-31 01:59:57 +00:00
|
|
|
rsx! {
|
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)));
|
|
|
|
|
2024-01-31 01:59:57 +00:00
|
|
|
rsx! { "{signal}" }
|
2023-12-16 00:35:48 +00:00
|
|
|
}
|