Make cargo check --all --examples work!

This commit is contained in:
Jonathan Kelley committed 2024-01-19 14:19:49 -08:00
1 parent 08475af221
commit 83bce6ce97
40 files changed
+295 -399

No files matched your search

+7 -11
View File
@@ -4,22 +4,18 @@ use dioxus::prelude::*;
use dioxus_signals::Signal;
fn main() {
dioxus_desktop::launch(app);
// dioxus_desktop::launch(app);
}
// Because signal is never read in this component, this component will not rerun when the signal changes
fn app() -> Element {
// Because signal is never read in this component, this component will not rerun when the signal changes
use_context_provider(|| Signal::new(0));
rsx! {
Child {}
}
rsx! { Child {} }
}
// This component does read from the signal, so when the signal changes it will rerun
#[component]
fn Child() -> Element {
let signal: Signal<i32> = *use_context(cx).unwrap();
// This component does read from the signal, so when the signal changes it will rerun
rsx! {
"{signal}"
}
let signal: Signal<i32> = use_context();
rsx! { "{signal}" }
}
+9 -17
View File
@@ -1,37 +1,29 @@
#![allow(non_snake_case)]
use dioxus::prelude::*;
use dioxus_signals::*;
fn main() {
dioxus_desktop::launch(app);
// dioxus_desktop::launch(app);
}
fn app() -> Element {
let signal = use_signal(|| 0);
let mut signal = use_signal(|| 0);
use_future(|| async move {
loop {
tokio::time::sleep(std::time::Duration::from_secs(1)).await;
*signal.write() += 1;
signal += 1;
}
});
let local_state = use_signal(|| 0);
let computed = use_selector_with_dependencies((local_state.get(),), move |(local_state,)| {
let mut local_state = use_signal(|| 0);
let computed = use_selector_with_dependencies((&local_state(),), move |(local_state,)| {
local_state * 2 + signal.cloned()
});
println!("Running app");
rsx! {
button {
onclick: move |_| {
local_state.set(local_state.get() + 1);
},
"Add one"
}
div {
"{computed}"
}
button { onclick: move |_| local_state.set(local_state() + 1), "Add one" }
div { "{computed}" }
}
}
+48 -63
View File
@@ -1,11 +1,7 @@
#![allow(non_snake_case)]
use dioxus::prelude::*;
use dioxus_signals::{use_signal, use_signal_sync, Signal};
use generational_box::SyncStorage;
fn main() {
dioxus_desktop::launch(app);
// dioxus_desktop::launch(app);
}
#[derive(Clone, Copy)]
@@ -15,76 +11,65 @@ enum ErrorComponent {
ReadDropped,
}
fn app(cx: Scope) -> Element {
let error = use_signal(cx, || None);
fn app() -> Element {
let mut error = use_signal(|| None as Option<ErrorComponent>);
render! {
match *error() {
match error() {
Some(ErrorComponent::Read) => render! { Read {} },
Some(ErrorComponent::ReadMut) => render! { ReadMut {} },
Some(ErrorComponent::ReadDropped) => render! { ReadDropped {} },
None => render! {
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"
}
}
}
}
}
fn Read(cx: Scope) -> Element {
let signal = use_signal_sync(cx, || 0);
let _write = signal.write();
let _read = signal.read();
todo!()
}
fn ReadMut(cx: Scope) -> Element {
let signal = use_signal_sync(cx, || 0);
let _read = signal.read();
let _write = signal.write();
todo!()
}
fn ReadDropped(cx: Scope) -> Element {
let signal = use_signal_sync(cx, || None);
if cx.generation() < 4 {
cx.needs_update();
}
render! {
if let Some(value) = &*signal() {
render!{"{value:?}"}
} else {
render! {
ReadDroppedSignalChild { parent_signal: signal }
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"}
}
}
}
}
#[component]
fn ReadDroppedSignalChild(
cx: Scope,
parent_signal: Signal<Option<Signal<i32, SyncStorage>>, SyncStorage>,
) -> Element {
let signal = use_signal_sync(cx, || 0);
cx.use_hook(move || {
parent_signal.set(Some(signal));
});
fn Read() -> Element {
let mut signal = use_signal_sync(|| 0);
let _write = signal.write();
let _read = signal.read();
todo!()
}
#[component]
fn ReadMut() -> Element {
let mut signal = use_signal_sync(|| 0);
let _read = signal.read();
let _write = signal.write();
todo!()
}
#[component]
fn ReadDropped() -> Element {
let signal = use_signal_sync(|| None as Option<SyncSignal<i32>>);
if generation() < 4 {
needs_update();
}
render! {
"{signal}"
if let Some(value) = signal() {
"{value:?}"
} else {
ReadDroppedSignalChild { parent_signal: signal }
}
}
}
#[component]
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}" }
}
+3 -3
View File
@@ -2,17 +2,17 @@ use dioxus::prelude::*;
use dioxus_signals::*;
fn main() {
dioxus_desktop::launch(App);
// dioxus_desktop::launch(App);
}
#[component]
fn App() -> Element {
let signal = use_signal(|| 0);
let mut signal = use_signal(|| 0);
let doubled = use_selector(move || signal * 2);
rsx! {
button {
onclick: move |_| *signal.write() += 1,
onclick: move |_| signal += 1,
"Increase"
}
Child { signal: doubled }
+8 -11
View File
@@ -2,25 +2,22 @@ use dioxus::prelude::*;
use dioxus_signals::*;
fn main() {
tracing_subscriber::fmt::init();
dioxus_desktop::launch(App);
// dioxus_desktop::launch(App);
}
#[component]
fn App(cx: Scope) -> Element {
let mut signal = use_signal_sync(cx, || 0);
cx.use_hook(|| {
fn App() -> Element {
let mut signal = use_signal_sync(|| 0);
use_hook(|| {
std::thread::spawn(move || loop {
std::thread::sleep(std::time::Duration::from_secs(1));
signal += 1;
})
});
});
render! {
button {
onclick: move |_| signal += 1,
"Increase"
}
rsx! {
button { onclick: move |_| signal += 1, "Increase" }
"{signal}"
}
}
@@ -4,7 +4,7 @@ use dioxus::prelude::*;
use dioxus_signals::Signal;
fn main() {
dioxus_desktop::launch(app);
// dioxus_desktop::launch(app);
}
#[derive(Clone, Copy, Default)]
@@ -14,10 +14,6 @@ struct ApplicationData {
many_signals: Signal<Vec<Signal<i32>>>,
}
fn use_app_data() -> ApplicationData {
*use_context(cx).unwrap()
}
fn app() -> Element {
use_context_provider(ApplicationData::default);
@@ -28,9 +24,10 @@ fn app() -> Element {
}
}
#[component]
fn ReadsFirst() -> Element {
println!("running first");
let data = use_app_data(cx);
let mut data = use_context::<ApplicationData>();
rsx! {
button {
@@ -55,54 +52,37 @@ fn ReadsFirst() -> Element {
}
}
#[component]
fn ReadsSecond() -> Element {
println!("running second");
let data = use_app_data(cx);
let mut data = use_context::<ApplicationData>();
rsx! {
button {
onclick: move |_| {
*data.second_data.write() += 1;
},
"Increase"
}
button {
onclick: move |_| {
*data.second_data.write() -= 1;
},
"Decrease"
}
button {
onclick: move |_| {
*data.second_data.write() = 0;
},
"Reset"
}
button { onclick: move |_| data.second_data += 1, "Increase" }
button { onclick: move |_| data.second_data -= 1, "Decrease" }
button { onclick: move |_| data.second_data.set(0), "Reset" }
"{data.second_data}"
}
}
#[component]
fn ReadsManySignals() -> Element {
println!("running many signals");
let data = use_app_data(cx);
let mut data = use_context::<ApplicationData>();
rsx! {
button {
onclick: move |_| {
data.many_signals.write().push(Signal::new(0));
},
onclick: move |_| data.many_signals.write().push(Signal::new(0)),
"Create"
}
button {
onclick: move |_| {
data.many_signals.write().pop();
},
onclick: move |_| { data.many_signals.write().pop(); },
"Destroy"
}
button {
onclick: move |_| {
if let Some(first) = data.many_signals.read().first() {
*first.write() += 1;
if let Some(mut first) = data.many_signals.read().first().cloned() {
first += 1;
}
},
"Increase First Item"
@@ -113,30 +93,15 @@ fn ReadsManySignals() -> Element {
}
}
#[derive(Props, PartialEq)]
struct ChildProps {
count: Signal<i32>,
}
fn Child(cx: Scope<ChildProps>) -> Element {
#[component]
fn Child(mut count: Signal<i32>) -> Element {
println!("running child");
let count = cx.props.count;
rsx! {
div {
"Child: {count}"
button {
onclick: move |_| {
*count.write() += 1;
},
"Increase"
}
button {
onclick: move |_| {
*count.write() -= 1;
},
"Decrease"
}
button { onclick: move |_| count += 1, "Increase" }
button { onclick: move |_| count -= 1, "Decrease" }
}
}
}