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

@@ -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" }
}
}
}