Fix the router and stub out a number of crates to get compiling

This commit is contained in:
Jonathan Kelley committed 2024-01-13 20:51:37 -08:00
1 parent 4c6e515da4
commit fae0b08e61
226 files changed
+1053 -1478

No files matched your search

Generated
+1 -258
View File
@@ -212,12 +212,6 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344" checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344"
[[package]]
name = "anymap"
version = "1.0.0-beta.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f1f8f5a6f3d50d89e3797d7593a50f96bb2aaa20ca0cc7be1fb673232c91d72"
[[package]] [[package]]
name = "anymap2" name = "anymap2"
version = "0.13.0" version = "0.13.0"
@@ -1396,12 +1390,6 @@ dependencies = [
"toml 0.8.2", "toml 0.8.2",
] ]
[[package]]
name = "cassowary"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
[[package]] [[package]]
name = "cast" name = "cast"
version = "0.3.0" version = "0.3.0"
@@ -2001,47 +1989,6 @@ version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345"
[[package]]
name = "crossterm"
version = "0.26.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a84cda67535339806297f1b331d6dd6320470d2a0fe65381e79ee9e156dd3d13"
dependencies = [
"bitflags 1.3.2",
"crossterm_winapi",
"libc",
"mio",
"parking_lot",
"signal-hook",
"signal-hook-mio",
"winapi",
]
[[package]]
name = "crossterm"
version = "0.27.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f476fe445d41c9e991fd07515a6f463074b782242ccf4a5b7b1d1012e70824df"
dependencies = [
"bitflags 2.4.1",
"crossterm_winapi",
"libc",
"mio",
"parking_lot",
"signal-hook",
"signal-hook-mio",
"winapi",
]
[[package]]
name = "crossterm_winapi"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acdd7c62a3665c7f6830a51635d9ac9b23ed385797f70a83bb8bafe9c572ab2b"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "cruet" name = "cruet"
version = "0.14.0" version = "0.14.0"
@@ -2621,7 +2568,6 @@ dependencies = [
"dioxus-signals", "dioxus-signals",
"dioxus-ssr", "dioxus-ssr",
"env_logger", "env_logger",
"fermi",
"futures-util", "futures-util",
"http-range", "http-range",
"im-rc", "im-rc",
@@ -2653,7 +2599,7 @@ dependencies = [
name = "dioxus-fullstack" name = "dioxus-fullstack"
version = "0.4.3" version = "0.4.3"
dependencies = [ dependencies = [
"anymap 0.12.1", "anymap",
"async-trait", "async-trait",
"axum 0.6.20", "axum 0.6.20",
"base64 0.21.7", "base64 0.21.7",
@@ -2817,40 +2763,6 @@ dependencies = [
"dioxus-desktop", "dioxus-desktop",
] ]
[[package]]
name = "dioxus-native-core"
version = "0.4.3"
dependencies = [
"anymap 1.0.0-beta.2",
"dashmap",
"dioxus",
"dioxus-core",
"dioxus-native-core",
"dioxus-native-core-macro",
"keyboard-types",
"lightningcss",
"parking_lot",
"rand 0.8.5",
"rustc-hash",
"shipyard",
"smallvec",
"taffy",
"tokio",
]
[[package]]
name = "dioxus-native-core-macro"
version = "0.4.3"
dependencies = [
"anymap 0.12.1",
"dioxus",
"dioxus-native-core",
"quote",
"rustc-hash",
"smallvec",
"syn 2.0.48",
]
[[package]] [[package]]
name = "dioxus-playwright-fullstack-test" name = "dioxus-playwright-fullstack-test"
version = "0.1.0" version = "0.1.0"
@@ -2997,24 +2909,6 @@ dependencies = [
"manganis", "manganis",
] ]
[[package]]
name = "dioxus-tui"
version = "0.4.3"
dependencies = [
"criterion 0.3.6",
"crossterm 0.26.1",
"dioxus",
"dioxus-core",
"dioxus-hot-reload",
"dioxus-html",
"dioxus-native-core",
"dioxus-native-core-macro",
"futures",
"plasmo",
"taffy",
"tokio",
]
[[package]] [[package]]
name = "dioxus-web" name = "dioxus-web"
version = "0.4.3" version = "0.4.3"
@@ -4651,12 +4545,6 @@ dependencies = [
"system-deps", "system-deps",
] ]
[[package]]
name = "grid"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eec1c01eb1de97451ee0d60de7d81cf1e72aabefb021616027f3d1c3ec1c723c"
[[package]] [[package]]
name = "group" name = "group"
version = "0.13.0" version = "0.13.0"
@@ -5544,15 +5432,6 @@ dependencies = [
"either", "either",
] ]
[[package]]
name = "itertools"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
dependencies = [
"either",
]
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.12.0" version = "0.12.0"
@@ -6070,15 +5949,6 @@ dependencies = [
"hashbrown 0.13.2", "hashbrown 0.13.2",
] ]
[[package]]
name = "lru"
version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2994eeba8ed550fd9b47a0b38f0242bc3344e496483c6180b69139cc2fa5d1d7"
dependencies = [
"hashbrown 0.14.3",
]
[[package]] [[package]]
name = "lru-cache" name = "lru-cache"
version = "0.1.2" version = "0.1.2"
@@ -7567,28 +7437,6 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a" checksum = "69d3587f8a9e599cc7ec2c00e331f71c4e69a5f9a4b8a6efd5b07466b9736f9a"
[[package]]
name = "plasmo"
version = "0.4.3"
dependencies = [
"anyhow",
"anymap 1.0.0-beta.2",
"criterion 0.3.6",
"crossterm 0.26.1",
"dioxus-html",
"dioxus-native-core",
"dioxus-native-core-macro",
"futures",
"futures-channel",
"once_cell",
"ratatui",
"rustc-hash",
"shipyard",
"smallvec",
"taffy",
"tokio",
]
[[package]] [[package]]
name = "platforms" name = "platforms"
version = "3.3.0" version = "3.3.0"
@@ -8043,24 +7891,6 @@ dependencies = [
"rand_core 0.6.4", "rand_core 0.6.4",
] ]
[[package]]
name = "ratatui"
version = "0.24.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ebc917cfb527a566c37ecb94c7e3fd098353516fb4eb6bea17015ade0182425"
dependencies = [
"bitflags 2.4.1",
"cassowary",
"crossterm 0.27.0",
"indoc",
"itertools 0.11.0",
"lru 0.12.1",
"paste",
"strum",
"unicode-segmentation",
"unicode-width",
]
[[package]] [[package]]
name = "rav1e" name = "rav1e"
version = "0.6.6" version = "0.6.6"
@@ -9420,50 +9250,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
[[package]]
name = "shipyard"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3511ae730f2e1c3d62a9025e2f9b2acbf130968057f1b3caab6d74a54a5e0e56"
dependencies = [
"hashbrown 0.12.3",
"lock_api",
"rayon",
"shipyard_proc",
]
[[package]]
name = "shipyard_proc"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3eb847f4b9582e468198b5cfb5731b65cc67fe5e535acc9cbf3c11703d15f08c"
dependencies = [
"proc-macro2",
"quote",
"syn 1.0.109",
]
[[package]]
name = "signal-hook"
version = "0.3.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8621587d4798caf8eb44879d42e56b9a93ea5dcd315a6487c357130095b62801"
dependencies = [
"libc",
"signal-hook-registry",
]
[[package]]
name = "signal-hook-mio"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29ad2e15f37ec9a6cc544097b78a1ec90001e9f71b81338ca39f430adaca99af"
dependencies = [
"libc",
"mio",
"signal-hook",
]
[[package]] [[package]]
name = "signal-hook-registry" name = "signal-hook-registry"
version = "1.4.1" version = "1.4.1"
@@ -9571,15 +9357,6 @@ dependencies = [
"rustc-hash", "rustc-hash",
] ]
[[package]]
name = "slotmap"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbff4acf519f630b3a3ddcfaea6c06b42174d9a44bc70c620e9ed1649d58b82a"
dependencies = [
"version_check",
]
[[package]] [[package]]
name = "smallbox" name = "smallbox"
version = "0.8.2" version = "0.8.2"
@@ -10010,28 +9787,6 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "strum"
version = "0.25.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290d54ea6f91c969195bdbcd7442c8c2a2ba87da8bf60a7ee86a235d4bc1e125"
dependencies = [
"strum_macros",
]
[[package]]
name = "strum_macros"
version = "0.25.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23dc1fa9ac9c169a78ba62f0b841814b7abae11bdd047b9c58f893439e309ea0"
dependencies = [
"heck 0.4.1",
"proc-macro2",
"quote",
"rustversion",
"syn 2.0.48",
]
[[package]] [[package]]
name = "subprocess" name = "subprocess"
version = "0.2.9" version = "0.2.9"
@@ -10132,18 +9887,6 @@ dependencies = [
"version-compare", "version-compare",
] ]
[[package]]
name = "taffy"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3c2287b6d7f721ada4cddf61ade5e760b2c6207df041cac9bfaa192897362fd3"
dependencies = [
"arrayvec",
"grid",
"num-traits",
"slotmap",
]
[[package]] [[package]]
name = "tao" name = "tao"
version = "0.24.0" version = "0.24.0"
+11 -11
View File
@@ -17,15 +17,15 @@ members = [
"packages/desktop", "packages/desktop",
"packages/mobile", "packages/mobile",
"packages/interpreter", "packages/interpreter",
"packages/fermi", # "packages/fermi",
"packages/liveview", "packages/liveview",
"packages/autofmt", "packages/autofmt",
"packages/check", "packages/check",
"packages/rsx", "packages/rsx",
"packages/dioxus-tui", # "packages/dioxus-tui",
"packages/rink", # "packages/rink",
"packages/native-core", # "packages/native-core",
"packages/native-core-macro", # "packages/native-core-macro",
"packages/rsx-rosetta", "packages/rsx-rosetta",
"packages/generational-box", "packages/generational-box",
"packages/signals", "packages/signals",
@@ -69,15 +69,15 @@ dioxus-ssr = { path = "packages/ssr", version = "0.4.0" }
dioxus-desktop = { path = "packages/desktop", version = "0.4.0" } dioxus-desktop = { path = "packages/desktop", version = "0.4.0" }
dioxus-mobile = { path = "packages/mobile", version = "0.4.0" } dioxus-mobile = { path = "packages/mobile", version = "0.4.0" }
dioxus-interpreter-js = { path = "packages/interpreter", version = "0.4.0" } dioxus-interpreter-js = { path = "packages/interpreter", version = "0.4.0" }
fermi = { path = "packages/fermi", version = "0.4.0" } # fermi = { path = "packages/fermi", version = "0.4.0" }
dioxus-liveview = { path = "packages/liveview", version = "0.4.0" } dioxus-liveview = { path = "packages/liveview", version = "0.4.0" }
dioxus-autofmt = { path = "packages/autofmt", version = "0.4.0" } dioxus-autofmt = { path = "packages/autofmt", version = "0.4.0" }
dioxus-check = { path = "packages/check", version = "0.4.0" } dioxus-check = { path = "packages/check", version = "0.4.0" }
dioxus-rsx = { path = "packages/rsx", version = "0.4.0" } dioxus-rsx = { path = "packages/rsx", version = "0.4.0" }
dioxus-tui = { path = "packages/dioxus-tui", version = "0.4.0" } # dioxus-tui = { path = "packages/dioxus-tui", version = "0.4.0" }
plasmo = { path = "packages/rink", version = "0.4.0" } # plasmo = { path = "packages/rink", version = "0.4.0" }
dioxus-native-core = { path = "packages/native-core", version = "0.4.0" } # dioxus-native-core = { path = "packages/native-core", version = "0.4.0" }
dioxus-native-core-macro = { path = "packages/native-core-macro", version = "0.4.0" } # dioxus-native-core-macro = { path = "packages/native-core-macro", version = "0.4.0" }
rsx-rosetta = { path = "packages/rsx-rosetta", version = "0.4.0" } rsx-rosetta = { path = "packages/rsx-rosetta", version = "0.4.0" }
dioxus-signals = { path = "packages/signals" } dioxus-signals = { path = "packages/signals" }
dioxus-cli-config = { path = "packages/cli-config", version = "0.4.1" } dioxus-cli-config = { path = "packages/cli-config", version = "0.4.1" }
@@ -126,7 +126,7 @@ dioxus-desktop = { workspace = true, features = ["transparent"] }
dioxus-ssr = { workspace = true } dioxus-ssr = { workspace = true }
dioxus-router = { workspace = true } dioxus-router = { workspace = true }
dioxus-signals = { workspace = true } dioxus-signals = { workspace = true }
fermi = { workspace = true } # fermi = { workspace = true }
futures-util = "0.3.21" futures-util = "0.3.21"
log = "0.4.14" log = "0.4.14"
num-format = "0.4.0" num-format = "0.4.0"
+2 -2
View File
@@ -55,8 +55,8 @@
Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust. Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust.
```rust ```rust
fn app(cx: Scope) -> Element { fn app() -> Element {
let mut count = use_state(cx, || 0); let mut count = use_state(|| 0);
cx.render(rsx! { cx.render(rsx! {
h1 { "High-Five counter: {count}" } h1 { "High-Five counter: {count}" }
+1 -1
View File
@@ -8,7 +8,7 @@ fn main() {
dioxus_web::launch(app); dioxus_web::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! ( cx.render(rsx! (
div { div {
style: "text-align: center;", style: "text-align: center;",
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
align_content: "a", align_content: "a",
+2 -2
View File
@@ -40,8 +40,8 @@ const RECT_STYLE: &str = r#"
text-aligh: center; text-aligh: center;
"#; "#;
fn app(cx: Scope) -> Element { fn app() -> Element {
let events = use_ref(cx, std::collections::VecDeque::new); let events = use_ref(std::collections::VecDeque::new);
let log_event = move |event: Event| { let log_event = move |event: Event| {
let mut events = events.write(); let mut events = events.write();
-73
View File
@@ -1,73 +0,0 @@
#![allow(non_snake_case)]
/*
Dioxus manages borrow lifetimes for you. This means any child may borrow from its parent. However, it is not possible
to hand out an &mut T to children - all props are consumed by &P, so you'd only get an &&mut T.
How does it work?
Dioxus will manually drop closures and props - things that borrow data before the component is ran again. This is done
"bottom up" from the lowest child all the way to the initiating parent. As it traverses each listener and prop, the
drop implementation is manually called, freeing any memory and ensuring that memory is not leaked.
We cannot drop from the parent to the children - if the drop implementation modifies the data, downstream references
might be broken since we take an &mut T and and &T to the data. Instead, we work bottom up, making sure to remove any
potential references to the data before finally giving out an &mut T. This prevents us from mutably aliasing the data,
and is proven to be safe with MIRI.
*/
use dioxus::prelude::*;
fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let text = cx.use_hook(|| vec![String::from("abc=def")]);
let first = text.get_mut(0).unwrap();
cx.render(rsx! {
div {
Child1 { text: first }
}
})
}
#[derive(Props)]
struct C1Props<'a> {
text: &'a mut String,
}
fn Child1<'a>(cx: Scope<'a, C1Props<'a>>) -> Element {
let (left, right) = cx.props.text.split_once('=').unwrap();
cx.render(rsx! {
div {
Child2 { text: left }
Child2 { text: right }
}
})
}
#[derive(Props)]
struct C2Props<'a> {
text: &'a str,
}
fn Child2<'a>(cx: Scope<'a, C2Props<'a>>) -> Element {
cx.render(rsx! {
Child3 { text: cx.props.text }
})
}
#[derive(Props)]
struct C3Props<'a> {
text: &'a str,
}
fn Child3<'a>(cx: Scope<'a, C3Props<'a>>) -> Element {
cx.render(rsx! {
div { "{cx.props.text}"}
})
}
+2 -2
View File
@@ -18,8 +18,8 @@ fn main() {
dioxus_desktop::launch_cfg(app, config); dioxus_desktop::launch_cfg(app, config);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let val = use_state(cx, || String::from("0")); let val = use_state(|| String::from("0"));
let input_digit = move |num: u8| { let input_digit = move |num: u8| {
if val.get() == "0" { if val.get() == "0" {
+2 -2
View File
@@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let login = use_callback!(cx, move |_| async move { let login = use_callback!(move |_| async move {
let res = reqwest::get("https://dog.ceo/api/breeds/list/all") let res = reqwest::get("https://dog.ceo/api/breeds/list/all")
.await .await
.unwrap() .unwrap()
+3 -3
View File
@@ -5,10 +5,10 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let mut count = use_signal(cx, || 0); let mut count = use_signal(|| 0);
use_future!(cx, || async move { use_future!(|| async move {
loop { loop {
tokio::time::sleep(std::time::Duration::from_millis(10)).await; tokio::time::sleep(std::time::Duration::from_millis(10)).await;
count += 1; count += 1;
+4 -4
View File
@@ -7,10 +7,10 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let emails_sent = use_ref(cx, Vec::new); let emails_sent = use_ref(Vec::new);
let tx = use_coroutine(cx, |mut rx: UnboundedReceiver<String>| { let tx = use_coroutine(|mut rx: UnboundedReceiver<String>| {
to_owned![emails_sent]; to_owned![emails_sent];
async move { async move {
while let Some(message) = rx.next().await { while let Some(message) = rx.next().await {
@@ -48,7 +48,7 @@ struct ComposeProps {
} }
fn compose(cx: Scope<ComposeProps>) -> Element { fn compose(cx: Scope<ComposeProps>) -> Element {
let user_input = use_state(cx, String::new); let user_input = use_state(String::new);
cx.render(rsx! { cx.render(rsx! {
div { div {
+4 -4
View File
@@ -6,11 +6,11 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let elements: &UseRef<Vec<Rc<MountedData>>> = use_ref(cx, Vec::new); let elements: &UseRef<Vec<Rc<MountedData>>> = use_ref(Vec::new);
let running = use_state(cx, || true); let running = use_state(|| true);
use_future!(cx, |(elements, running)| async move { use_future!(|(elements, running)| async move {
let mut focused = 0; let mut focused = 0;
if *running.current() { if *running.current() {
loop { loop {
+2 -2
View File
@@ -7,8 +7,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let counters = use_state(cx, || vec![0, 0, 0]); let counters = use_state(|| vec![0, 0, 0]);
let sum: usize = counters.iter().copied().sum(); let sum: usize = counters.iter().copied().sum();
render! { render! {
+11 -11
View File
@@ -27,8 +27,8 @@ pub struct Client {
type ClientContext = Vec<Client>; type ClientContext = Vec<Client>;
#[component] #[component]
fn App(cx: Scope) -> Element { fn App() -> Element {
use_shared_state_provider::<ClientContext>(cx, Default::default); use_shared_state_provider::<ClientContext>(Default::default);
render! { render! {
link { link {
@@ -53,8 +53,8 @@ fn App(cx: Scope) -> Element {
} }
#[component] #[component]
fn ClientList(cx: Scope) -> Element { fn ClientList() -> Element {
let clients = use_shared_state::<ClientContext>(cx).unwrap(); let clients = use_shared_state::<ClientContext>().unwrap();
cx.render(rsx! { cx.render(rsx! {
h2 { "List of Clients" } h2 { "List of Clients" }
@@ -75,11 +75,11 @@ fn ClientList(cx: Scope) -> Element {
} }
#[component] #[component]
fn ClientAdd(cx: Scope) -> Element { fn ClientAdd() -> Element {
let clients = use_shared_state::<ClientContext>(cx).unwrap(); let clients = use_shared_state::<ClientContext>().unwrap();
let first_name = use_state(cx, String::new); let first_name = use_state(String::new);
let last_name = use_state(cx, String::new); let last_name = use_state(String::new);
let description = use_state(cx, String::new); let description = use_state(String::new);
cx.render(rsx! { cx.render(rsx! {
h2 { "Add new Client" } h2 { "Add new Client" }
@@ -142,8 +142,8 @@ fn ClientAdd(cx: Scope) -> Element {
} }
#[component] #[component]
fn Settings(cx: Scope) -> Element { fn Settings() -> Element {
let clients = use_shared_state::<ClientContext>(cx).unwrap(); let clients = use_shared_state::<ClientContext>().unwrap();
cx.render(rsx! { cx.render(rsx! {
h2 { "Settings" } h2 { "Settings" }
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
p { p {
+1 -1
View File
@@ -31,7 +31,7 @@ fn main() {
); );
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
h1 {"hello world!"} h1 {"hello world!"}
+2 -2
View File
@@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let disabled = use_state(cx, || false); let disabled = use_state(|| false);
cx.render(rsx! { cx.render(rsx! {
div { div {
+4 -4
View File
@@ -12,9 +12,9 @@ struct ListBreeds {
#[component] #[component]
fn AppRoot(cx: Scope<'_>) -> Element { fn AppRoot(cx: Scope<'_>) -> Element {
let breed = use_state(cx, || "deerhound".to_string()); let breed = use_state(|| "deerhound".to_string());
let breeds = use_future!(cx, || async move { let breeds = use_future!(|| async move {
reqwest::get("https://dog.ceo/api/breeds/list/all") reqwest::get("https://dog.ceo/api/breeds/list/all")
.await .await
.unwrap() .unwrap()
@@ -51,8 +51,8 @@ struct DogApi {
} }
#[component] #[component]
fn BreedPic(cx: Scope, breed: String) -> Element { fn BreedPic(breed: String) -> Element {
let fut = use_future!(cx, |breed| async move { let fut = use_future!(|breed| async move {
reqwest::get(format!("https://dog.ceo/api/breed/{breed}/images/random")) reqwest::get(format!("https://dog.ceo/api/breed/{breed}/images/random"))
.await .await
.unwrap() .unwrap()
+2 -2
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let count = if cx.generation() % 2 == 0 { 10 } else { 0 }; let count = if cx.generation() % 2 == 0 { 10 } else { 0 };
println!("Generation: {}", cx.generation()); println!("Generation: {}", cx.generation());
@@ -20,7 +20,7 @@ fn app(cx: Scope) -> Element {
} }
} }
fn drop_child(cx: Scope) -> Element { fn drop_child() -> Element {
cx.use_hook(|| Drops); cx.use_hook(|| Drops);
render! { render! {
div{} div{}
+2 -2
View File
@@ -5,8 +5,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
use_asset_handler(cx, "logos", |request, response| { use_asset_handler("logos", |request, response| {
// Note that the "logos" prefix is stripped from the URI // Note that the "logos" prefix is stripped from the URI
// //
// However, the asset is absolute to its "virtual folder" - meaning it starts with a leading slash // However, the asset is absolute to its "virtual folder" - meaning it starts with a leading slash
+2 -2
View File
@@ -5,7 +5,7 @@ fn main() {
} }
#[component] #[component]
fn App(cx: Scope) -> Element { fn App() -> Element {
cx.render(rsx! { cx.render(rsx! {
ErrorBoundary { ErrorBoundary {
handle_error: |error: CapturedError| rsx! {"Found error {error}"}, handle_error: |error: CapturedError| rsx! {"Found error {error}"},
@@ -17,7 +17,7 @@ fn App(cx: Scope) -> Element {
} }
#[component] #[component]
fn DemoC(cx: Scope, x: i32) -> Element { fn DemoC(x: i32) -> Element {
let result = Err("Error"); let result = Err("Error");
result.throw()?; result.throw()?;
+2 -2
View File
@@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let future = use_future(cx, (), |_| async move { let future = use_future((), |_| async move {
let eval = eval( let eval = eval(
r#" r#"
dioxus.send("Hi from JS!"); dioxus.send("Hi from JS!");
+6 -6
View File
@@ -9,9 +9,9 @@ fn main() {
static NAME: Atom<String> = Atom(|_| "world".to_string()); static NAME: Atom<String> = Atom(|_| "world".to_string());
fn app(cx: Scope) -> Element { fn app() -> Element {
use_init_atom_root(cx); use_init_atom_root(cx);
let name = use_read(cx, &NAME); let name = use_read(&NAME);
cx.render(rsx! { cx.render(rsx! {
div { "hello {name}!" } div { "hello {name}!" }
@@ -20,8 +20,8 @@ fn app(cx: Scope) -> Element {
}) })
} }
fn Child(cx: Scope) -> Element { fn Child() -> Element {
let set_name = use_set(cx, &NAME); let set_name = use_set(&NAME);
cx.render(rsx! { cx.render(rsx! {
button { button {
@@ -33,8 +33,8 @@ fn Child(cx: Scope) -> Element {
static NAMES: AtomRef<Vec<String>> = AtomRef(|_| vec!["world".to_string()]); static NAMES: AtomRef<Vec<String>> = AtomRef(|_| vec!["world".to_string()]);
fn ChildWithRef(cx: Scope) -> Element { fn ChildWithRef() -> Element {
let names = use_atom_ref(cx, &NAMES); let names = use_atom_ref(&NAMES);
cx.render(rsx! { cx.render(rsx! {
div { div {
+2 -2
View File
@@ -20,8 +20,8 @@ fn main() {
const _STYLE: &str = manganis::mg!(file("./examples/assets/fileexplorer.css")); const _STYLE: &str = manganis::mg!(file("./examples/assets/fileexplorer.css"));
fn app(cx: Scope) -> Element { fn app() -> Element {
let files = use_ref(cx, Files::new); let files = use_ref(Files::new);
cx.render(rsx! { cx.render(rsx! {
div { div {
+3 -3
View File
@@ -7,9 +7,9 @@ fn main() {
dioxus_desktop::launch(App); dioxus_desktop::launch(App);
} }
fn App(cx: Scope) -> Element { fn App() -> Element {
let enable_directory_upload = use_state(cx, || false); let enable_directory_upload = use_state(|| false);
let files_uploaded: &UseRef<Vec<String>> = use_ref(cx, Vec::new); let files_uploaded: &UseRef<Vec<String>> = use_ref(Vec::new);
cx.render(rsx! { cx.render(rsx! {
label { label {
+1 -1
View File
@@ -10,7 +10,7 @@ fn main() {
dioxus_desktop::launch_with_props(app, (), cfg); dioxus_desktop::launch_with_props(app, (), cfg);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx!( cx.render(rsx!(
div { div {
h1 { "drag a file here and check your console" } h1 { "drag a file here and check your console" }
+6 -6
View File
@@ -15,7 +15,7 @@ fn main() {
} }
#[component] #[component]
fn App(cx: Scope) -> Element { fn App() -> Element {
render! { render! {
Router::<Route> {} Router::<Route> {}
} }
@@ -36,7 +36,7 @@ enum Route {
} }
#[component] #[component]
fn Footer(cx: Scope) -> Element { fn Footer() -> Element {
render! { render! {
div { div {
Outlet::<Route> { } Outlet::<Route> { }
@@ -58,21 +58,21 @@ fn Footer(cx: Scope) -> Element {
} }
#[component] #[component]
fn Home(cx: Scope) -> Element { fn Home() -> Element {
render!("Home") render!("Home")
} }
#[component] #[component]
fn Games(cx: Scope) -> Element { fn Games() -> Element {
render!("Games") render!("Games")
} }
#[component] #[component]
fn Play(cx: Scope) -> Element { fn Play() -> Element {
render!("Play") render!("Play")
} }
#[component] #[component]
fn Settings(cx: Scope) -> Element { fn Settings() -> Element {
render!("Settings") render!("Settings")
} }
+1 -1
View File
@@ -9,7 +9,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
h1 { "Form" } h1 { "Form" }
+4 -4
View File
@@ -31,9 +31,9 @@ impl Label {
} }
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let items = use_ref(cx, Vec::new); let items = use_ref(Vec::new);
let selected = use_state(cx, || None); let selected = use_state(|| None);
cx.render(rsx! { cx.render(rsx! {
div { class: "container", div { class: "container",
@@ -97,7 +97,7 @@ struct ActionButtonProps<'a> {
onclick: EventHandler<'a>, onclick: EventHandler<'a>,
} }
fn ActionButton<'a>(cx: Scope<'a, ActionButtonProps<'a>>) -> Element { fn ActionButton(props: ActionButtonProps) -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
class: "col-sm-6 smallpad", class: "col-sm-6 smallpad",
+1 -1
View File
@@ -6,7 +6,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
render! { render! {
generic_child { data: 0 } generic_child { data: 0 }
} }
+1 -1
View File
@@ -13,7 +13,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
// This is discouraged // This is discouraged
std::thread::sleep(std::time::Duration::from_millis(2_000)); std::thread::sleep(std::time::Duration::from_millis(2_000));
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
render! { render! {
div { "Hello, world!" } div { "Hello, world!" }
} }
+2 -2
View File
@@ -20,8 +20,8 @@ fn main() {
dioxus_desktop::launch_cfg(app, Config::new().with_prerendered(content)); dioxus_desktop::launch_cfg(app, Config::new().with_prerendered(content));
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let val = use_state(cx, || 0); let val = use_state(|| 0);
cx.render(rsx! { cx.render(rsx! {
div { div {
+6 -6
View File
@@ -5,22 +5,22 @@
use dioxus::prelude::*; use dioxus::prelude::*;
#[component] #[component]
fn Thing1<T>(cx: Scope, _a: T) -> Element { fn Thing1<T>(_a: T) -> Element {
cx.render(rsx! { "" }) cx.render(rsx! { "" })
} }
#[component] #[component]
fn Thing2(cx: Scope, _a: u32) -> Element<'a> { fn Thing2(_a: u32) -> Element {
cx.render(rsx! { "" }) cx.render(rsx! { "" })
} }
#[component] #[component]
fn Thing3<'a, T>(cx: Scope<'a>, _a: &'a T) -> Element<'a> { fn Thing3<'a, T>(cx: Scope<'a>, _a: &'a T) -> Element {
cx.render(rsx! { "" }) cx.render(rsx! { "" })
} }
#[component] #[component]
fn Thing4<'a>(cx: Scope<'a>, _a: &'a u32) -> Element<'a> { fn Thing4<'a>(cx: Scope<'a>, _a: &'a u32) -> Element {
cx.render(rsx! { "" }) cx.render(rsx! { "" })
} }
@@ -29,8 +29,8 @@ fn main() {
} }
#[component] #[component]
fn App(cx: Scope) -> Element { fn App() -> Element {
let state = use_state(cx, || 1); let state = use_state(|| 1);
cx.render(rsx! { cx.render(rsx! {
div { div {
+2 -2
View File
@@ -34,7 +34,7 @@ const FIELDS: &[(&str, &str)] = &[
("week", ""), // degrades to text most of the time ("week", ""), // degrades to text most of the time
]; ];
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { margin_left: "30px", div { margin_left: "30px",
{select_example(cx)}, {select_example(cx)},
@@ -136,7 +136,7 @@ fn app(cx: Scope) -> Element {
}) })
} }
fn select_example(cx: Scope) -> Element { fn select_example() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
select { select {
+4 -4
View File
@@ -6,7 +6,7 @@ fn main() {
} }
#[component] #[component]
fn App(cx: Scope) -> Element { fn App() -> Element {
cx.render(rsx! ( cx.render(rsx! (
div { div {
p { p {
@@ -38,7 +38,7 @@ enum Route {
} }
#[component] #[component]
fn Header(cx: Scope) -> Element { fn Header() -> Element {
render! { render! {
h1 { "Your app here" } h1 { "Your app here" }
ul { ul {
@@ -50,11 +50,11 @@ fn Header(cx: Scope) -> Element {
} }
#[component] #[component]
fn Home(cx: Scope) -> Element { fn Home() -> Element {
render!(h1 { "Home" }) render!(h1 { "Home" })
} }
#[component] #[component]
fn Settings(cx: Scope) -> Element { fn Settings() -> Element {
render!(h1 { "Settings" }) render!(h1 { "Settings" })
} }
+1 -1
View File
@@ -7,7 +7,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let onsubmit = move |evt: FormEvent| async move { let onsubmit = move |evt: FormEvent| async move {
let resp = reqwest::Client::new() let resp = reqwest::Client::new()
.post("http://localhost:8080/login") .post("http://localhost:8080/login")
+1 -1
View File
@@ -59,7 +59,7 @@ pub fn main() -> Result<()> {
Ok(()) Ok(())
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let items = cx.use_hook(|| vec![1, 2, 3]); let items = cx.use_hook(|| vec![1, 2, 3]);
log::debug!("Hello from the app"); log::debug!("Hello from the app");
+2 -2
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
button { button {
@@ -18,7 +18,7 @@ fn app(cx: Scope) -> Element {
}) })
} }
fn popup(cx: Scope) -> Element { fn popup() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { "This is a popup!" } div { "This is a popup!" }
}) })
+1 -1
View File
@@ -10,7 +10,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
onclick: move |_| println!("clicked! top"), onclick: move |_| println!("clicked! top"),
+3 -3
View File
@@ -30,14 +30,14 @@ pub static DIOXUS_FRONT_ISSUER_URL: &str = env!("DIOXUS_FRONT_ISSUER_URL");
pub static DIOXUS_FRONT_CLIENT_ID: &str = env!("DIOXUS_FRONT_CLIENT_ID"); pub static DIOXUS_FRONT_CLIENT_ID: &str = env!("DIOXUS_FRONT_CLIENT_ID");
pub static DIOXUS_FRONT_URL: &str = env!("DIOXUS_FRONT_URL"); pub static DIOXUS_FRONT_URL: &str = env!("DIOXUS_FRONT_URL");
fn App(cx: Scope) -> Element { fn App() -> Element {
use_init_atom_root(cx); use_init_atom_root(cx);
// Retrieve the value stored in the browser's storage // Retrieve the value stored in the browser's storage
let stored_auth_token = LocalStorage::get(DIOXUS_FRONT_AUTH_TOKEN) let stored_auth_token = LocalStorage::get(DIOXUS_FRONT_AUTH_TOKEN)
.ok() .ok()
.unwrap_or(AuthTokenState::default()); .unwrap_or(AuthTokenState::default());
let fermi_auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN); let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
if fermi_auth_token.read().is_none() { if fermi_auth_token.read().is_none() {
*fermi_auth_token.write() = Some(stored_auth_token); *fermi_auth_token.write() = Some(stored_auth_token);
} }
@@ -45,7 +45,7 @@ fn App(cx: Scope) -> Element {
let stored_auth_request = LocalStorage::get(DIOXUS_FRONT_AUTH_REQUEST) let stored_auth_request = LocalStorage::get(DIOXUS_FRONT_AUTH_REQUEST)
.ok() .ok()
.unwrap_or(AuthRequestState::default()); .unwrap_or(AuthRequestState::default());
let fermi_auth_request = use_atom_ref(cx, &FERMI_AUTH_REQUEST); let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
if fermi_auth_request.read().is_none() { if fermi_auth_request.read().is_none() {
*fermi_auth_request.write() = Some(stored_auth_request); *fermi_auth_request.write() = Some(stored_auth_request);
} }
@@ -15,9 +15,9 @@ use openidconnect::{url::Url, OAuth2TokenResponse, TokenResponse};
#[component] #[component]
pub fn LogOut(cx: Scope<ClientProps>) -> Element { pub fn LogOut(cx: Scope<ClientProps>) -> Element {
let fermi_auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN); let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
let fermi_auth_token_read = fermi_auth_token.read().clone(); let fermi_auth_token_read = fermi_auth_token.read().clone();
let log_out_url_state = use_state(cx, || None::<Option<Result<Url, crate::errors::Error>>>); let log_out_url_state = use_state(|| None::<Option<Result<Url, crate::errors::Error>>>);
cx.render(match fermi_auth_token_read { cx.render(match fermi_auth_token_read {
Some(fermi_auth_token_read) => match fermi_auth_token_read.id_token.clone() { Some(fermi_auth_token_read) => match fermi_auth_token_read.id_token.clone() {
Some(id_token) => match log_out_url_state.get() { Some(id_token) => match log_out_url_state.get() {
@@ -76,8 +76,8 @@ pub fn LogOut(cx: Scope<ClientProps>) -> Element {
#[component] #[component]
pub fn RefreshToken(cx: Scope<ClientProps>) -> Element { pub fn RefreshToken(cx: Scope<ClientProps>) -> Element {
let fermi_auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN); let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
let fermi_auth_request = use_atom_ref(cx, &FERMI_AUTH_REQUEST); let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
let fermi_auth_token_read = fermi_auth_token.read().clone(); let fermi_auth_token_read = fermi_auth_token.read().clone();
cx.render(match fermi_auth_token_read { cx.render(match fermi_auth_token_read {
Some(fermi_auth_client_read) => match fermi_auth_client_read.refresh_token { Some(fermi_auth_client_read) => match fermi_auth_client_read.refresh_token {
@@ -128,9 +128,9 @@ pub fn RefreshToken(cx: Scope<ClientProps>) -> Element {
} }
#[component] #[component]
pub fn LoadClient(cx: Scope) -> Element { pub fn LoadClient() -> Element {
let init_client_future = use_future(cx, (), |_| async move { init_oidc_client().await }); let init_client_future = use_future((), |_| async move { init_oidc_client().await });
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(cx, &FERMI_CLIENT); let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(&FERMI_CLIENT);
cx.render(match init_client_future.value() { cx.render(match init_client_future.value() {
Some(client_props) => match client_props { Some(client_props) => match client_props {
Ok((client_id, client)) => { Ok((client_id, client)) => {
@@ -162,10 +162,10 @@ pub fn LoadClient(cx: Scope) -> Element {
} }
#[component] #[component]
pub fn AuthHeader(cx: Scope) -> Element { pub fn AuthHeader() -> Element {
let auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN); let auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
let fermi_auth_request = use_atom_ref(cx, &FERMI_AUTH_REQUEST); let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(cx, &FERMI_CLIENT); let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(&FERMI_CLIENT);
let client = fermi_client.read().oidc_client.clone(); let client = fermi_client.read().oidc_client.clone();
let auth_request_read = fermi_auth_request.read().clone(); let auth_request_read = fermi_auth_request.read().clone();
let auth_token_read = auth_token.read().clone(); let auth_token_read = auth_token.read().clone();
@@ -1,5 +1,5 @@
use dioxus::prelude::*; use dioxus::prelude::*;
pub fn Home(cx: Scope) -> Element { pub fn Home() -> Element {
render! { div { "Hello world" } } render! { div { "Hello world" } }
} }
@@ -10,11 +10,11 @@ use fermi::*;
use openidconnect::{OAuth2TokenResponse, TokenResponse}; use openidconnect::{OAuth2TokenResponse, TokenResponse};
#[component] #[component]
pub fn Login(cx: Scope, query_string: String) -> Element { pub fn Login(query_string: String) -> Element {
let fermi_client = use_atom_ref(cx, &FERMI_CLIENT); let fermi_client = use_atom_ref(&FERMI_CLIENT);
let fermi_auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN); let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
let home_url: NavigationTarget<Route> = DIOXUS_FRONT_URL.parse().unwrap(); let home_url: NavigationTarget<Route> = DIOXUS_FRONT_URL.parse().unwrap();
let fermi_auth_request = use_atom_ref(cx, &FERMI_AUTH_REQUEST); let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
let client = fermi_client.read().oidc_client.clone(); let client = fermi_client.read().oidc_client.clone();
let auth_token_read = fermi_auth_token.read().clone(); let auth_token_read = fermi_auth_token.read().clone();
cx.render(match (client, auth_token_read) { cx.render(match (client, auth_token_read) {
@@ -1,7 +1,7 @@
use dioxus::prelude::*; use dioxus::prelude::*;
#[component] #[component]
pub fn NotFound(cx: Scope, route: Vec<String>) -> Element { pub fn NotFound(route: Vec<String>) -> Element {
render! { render! {
div{ div{
{route.join("")} {route.join("")}
+1 -1
View File
@@ -10,7 +10,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
Button { Button {
a: "asd".to_string(), a: "asd".to_string(),
+1 -1
View File
@@ -5,7 +5,7 @@ fn main() {
dioxus_desktop::launch_cfg(app, make_config()); dioxus_desktop::launch_cfg(app, make_config());
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
width: "100%", width: "100%",
+7 -7
View File
@@ -37,8 +37,8 @@ fn main() {
const STYLE: &str = include_str!("./assets/calculator.css"); const STYLE: &str = include_str!("./assets/calculator.css");
fn app(cx: Scope) -> Element { fn app() -> Element {
let state = use_ref(cx, Calculator::new); let state = use_ref(Calculator::new);
cx.render(rsx! { cx.render(rsx! {
style { {STYLE} } style { {STYLE} }
@@ -121,13 +121,13 @@ fn app(cx: Scope) -> Element {
} }
#[derive(Props)] #[derive(Props)]
struct CalculatorKeyProps<'a> { struct CalculatorKeyProps {
name: &'a str, name: String,
onclick: EventHandler<'a, MouseEvent>, onclick: EventHandler<MouseEvent>,
children: Element<'a>, children: Element,
} }
fn CalculatorKey<'a>(cx: Scope<'a, CalculatorKeyProps<'a>>) -> Element { fn CalculatorKey(props: CalculatorKeyProps) -> Element {
cx.render(rsx! { cx.render(rsx! {
button { button {
class: "calculator-key {cx.props.name}", class: "calculator-key {cx.props.name}",
+2 -2
View File
@@ -14,8 +14,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let state = use_state(cx, PlayerState::new); let state = use_state(PlayerState::new);
cx.render(rsx!( cx.render(rsx!(
div { div {
+3 -3
View File
@@ -63,7 +63,7 @@ impl FromQuery for ManualBlogQuerySegments {
} }
#[component] #[component]
fn BlogPost(cx: Scope, query_params: ManualBlogQuerySegments) -> Element { fn BlogPost(query_params: ManualBlogQuerySegments) -> Element {
render! { render! {
div{"This is your blogpost with a query segment:"} div{"This is your blogpost with a query segment:"}
div{ "{query_params:?}" } div{ "{query_params:?}" }
@@ -71,7 +71,7 @@ fn BlogPost(cx: Scope, query_params: ManualBlogQuerySegments) -> Element {
} }
#[component] #[component]
fn AutomaticBlogPost(cx: Scope, name: String, surname: String) -> Element { fn AutomaticBlogPost(name: String, surname: String) -> Element {
render! { render! {
div{"This is your blogpost with a query segment:"} div{"This is your blogpost with a query segment:"}
div{ "name={name}&surname={surname}" } div{ "name={name}&surname={surname}" }
@@ -79,7 +79,7 @@ fn AutomaticBlogPost(cx: Scope, name: String, surname: String) -> Element {
} }
#[component] #[component]
fn App(cx: Scope) -> Element { fn App() -> Element {
render! { Router::<Route>{} } render! { Router::<Route>{} }
} }
+3 -3
View File
@@ -25,10 +25,10 @@ fn main() {
); );
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let div_element: &UseRef<Option<Rc<MountedData>>> = use_ref(cx, || None); let div_element: &UseRef<Option<Rc<MountedData>>> = use_ref(|| None);
let dimentions = use_ref(cx, Rect::zero); let dimentions = use_ref(Rect::zero);
cx.render(rsx!( cx.render(rsx!(
div { div {
+2 -2
View File
@@ -8,8 +8,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let mut count = use_state(cx, || 0); let mut count = use_state(|| 0);
cx.render(rsx! { cx.render(rsx! {
h1 { "High-Five counter: {count}" } h1 { "High-Five counter: {count}" }
+7 -7
View File
@@ -36,14 +36,14 @@ enum Route {
// ANCHOR_END: router // ANCHOR_END: router
#[component] #[component]
fn App(cx: Scope) -> Element { fn App() -> Element {
render! { render! {
Router::<Route> {} Router::<Route> {}
} }
} }
#[component] #[component]
fn NavBar(cx: Scope) -> Element { fn NavBar() -> Element {
render! { render! {
nav { nav {
ul { ul {
@@ -56,14 +56,14 @@ fn NavBar(cx: Scope) -> Element {
} }
#[component] #[component]
fn Home(cx: Scope) -> Element { fn Home() -> Element {
render! { render! {
h1 { "Welcome to the Dioxus Blog!" } h1 { "Welcome to the Dioxus Blog!" }
} }
} }
#[component] #[component]
fn Blog(cx: Scope) -> Element { fn Blog() -> Element {
render! { render! {
h1 { "Blog" } h1 { "Blog" }
Outlet::<Route> {} Outlet::<Route> {}
@@ -71,7 +71,7 @@ fn Blog(cx: Scope) -> Element {
} }
#[component] #[component]
fn BlogList(cx: Scope) -> Element { fn BlogList() -> Element {
render! { render! {
h2 { "Choose a post" } h2 { "Choose a post" }
ul { ul {
@@ -92,14 +92,14 @@ fn BlogList(cx: Scope) -> Element {
} }
#[component] #[component]
fn BlogPost(cx: Scope, name: String) -> Element { fn BlogPost(name: String) -> Element {
render! { render! {
h2 { "Blog Post: {name}"} h2 { "Blog Post: {name}"}
} }
} }
#[component] #[component]
fn PageNotFound(cx: Scope, route: Vec<String>) -> Element { fn PageNotFound(route: Vec<String>) -> Element {
render! { render! {
h1 { "Page not found" } h1 { "Page not found" }
p { "We are terribly sorry, but the page you requested doesn't exist." } p { "We are terribly sorry, but the page you requested doesn't exist." }
+4 -4
View File
@@ -12,15 +12,15 @@ fn main() {
renderer.render(&vdom); renderer.render(&vdom);
} }
fn example(cx: Scope) -> Element { fn example() -> Element {
let items = use_state(cx, || { let items = use_state(|| {
vec![Thing { vec![Thing {
a: "asd".to_string(), a: "asd".to_string(),
b: 10, b: 10,
}] }]
}); });
let things = use_ref(cx, || { let things = use_ref(|| {
vec![Thing { vec![Thing {
a: "asd".to_string(), a: "asd".to_string(),
b: 10, b: 10,
@@ -28,7 +28,7 @@ fn example(cx: Scope) -> Element {
}); });
let things_list = things.read(); let things_list = things.read();
let mything = use_ref(cx, || Some(String::from("asd"))); let mything = use_ref(|| Some(String::from("asd")));
let mything_read = mything.read(); let mything_read = mything.read();
cx.render(rsx!( cx.render(rsx!(
+8 -8
View File
@@ -49,7 +49,7 @@ use baller::Baller;
use dioxus::prelude::*; use dioxus::prelude::*;
#[component] #[component]
fn App(cx: Scope) -> Element { fn App() -> Element {
let formatting = "formatting!"; let formatting = "formatting!";
let formatting_tuple = ("a", "b"); let formatting_tuple = ("a", "b");
let lazy_fmt = format_args!("lazily formatted text"); let lazy_fmt = format_args!("lazily formatted text");
@@ -205,7 +205,7 @@ fn App(cx: Scope) -> Element {
// helper functions // helper functions
// Anything that implements IntoVnode can be dropped directly into Rsx // Anything that implements IntoVnode can be dropped directly into Rsx
{helper(cx, "hello world!")} {helper("hello world!")}
// Strings can be supplied directly // Strings can be supplied directly
{String::from("Hello world!")} {String::from("Hello world!")}
@@ -223,7 +223,7 @@ fn format_dollars(dollars: u32, cents: u32) -> String {
format!("${dollars}.{cents:02}") format!("${dollars}.{cents:02}")
} }
fn helper<'a>(cx: &'a ScopeState, text: &'a str) -> Element<'a> { fn helper<'a>(cx: &'a ScopeState, text: &'a str) -> Element {
cx.render(rsx! { cx.render(rsx! {
p { "{text}" } p { "{text}" }
}) })
@@ -233,7 +233,7 @@ fn helper<'a>(cx: &'a ScopeState, text: &'a str) -> Element<'a> {
// This will likely be deprecated/removed in a future update that will introduce a more polished linting system, // This will likely be deprecated/removed in a future update that will introduce a more polished linting system,
// something like Clippy. // something like Clippy.
#[component(no_case_check)] #[component(no_case_check)]
fn lowercase_helper(cx: Scope) -> Element { fn lowercase_helper() -> Element {
cx.render(rsx! { cx.render(rsx! {
"asd" "asd"
}) })
@@ -254,7 +254,7 @@ mod baller {
// This will likely be deprecated/removed in a future update that will introduce a more polished linting system, // This will likely be deprecated/removed in a future update that will introduce a more polished linting system,
// something like Clippy. // something like Clippy.
#[component(no_case_check)] #[component(no_case_check)]
pub fn lowercase_component(cx: Scope) -> Element { pub fn lowercase_component() -> Element {
cx.render(rsx! { "look ma, no uppercase" }) cx.render(rsx! { "look ma, no uppercase" })
} }
} }
@@ -263,12 +263,12 @@ mod baller {
pub struct TallerProps<'a> { pub struct TallerProps<'a> {
/// Fields are documented and accessible in rsx! /// Fields are documented and accessible in rsx!
a: &'static str, a: &'static str,
children: Element<'a>, children: Element,
} }
/// Documention for this component is visible within the rsx macro /// Documention for this component is visible within the rsx macro
#[component] #[component]
pub fn Taller<'a>(cx: Scope<'a, TallerProps<'a>>) -> Element { pub fn Taller(props: TallerProps -> Element {
cx.render(rsx! { cx.render(rsx! {
{&cx.props.children} {&cx.props.children}
}) })
@@ -297,7 +297,7 @@ fn WithInline<'a>(cx: Scope<'a>, text: &'a str) -> Element {
} }
#[component] #[component]
fn Label<T>(cx: Scope, text: T) -> Element fn Label<T>(text: T) -> Element
where where
T: Display, T: Display,
{ {
+2 -2
View File
@@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let header_element = use_ref(cx, || None); let header_element = use_ref(|| None);
cx.render(rsx!( cx.render(rsx!(
div { div {
+6 -6
View File
@@ -27,8 +27,8 @@ impl CoolData {
#[component] #[component]
#[rustfmt::skip] #[rustfmt::skip]
pub fn App(cx: Scope) -> Element { pub fn App() -> Element {
use_shared_state_provider(cx, || CoolData::new(HashMap::from([ use_shared_state_provider(|| CoolData::new(HashMap::from([
(0, "Hello, World!".to_string()), (0, "Hello, World!".to_string()),
(1, "Dioxus is amazing!".to_string()) (1, "Dioxus is amazing!".to_string())
]))); ])));
@@ -50,8 +50,8 @@ pub fn App(cx: Scope) -> Element {
} }
#[component] #[component]
fn DataEditor(cx: Scope, id: usize) -> Element { fn DataEditor(id: usize) -> Element {
let data = use_shared_state::<CoolData>(cx)?; let data = use_shared_state::<CoolData>()?;
render! { render! {
p { p {
@@ -61,8 +61,8 @@ fn DataEditor(cx: Scope, id: usize) -> Element {
} }
#[component] #[component]
fn DataView(cx: Scope, id: usize) -> Element { fn DataView(id: usize) -> Element {
let data = use_shared_state::<CoolData>(cx)?; let data = use_shared_state::<CoolData>()?;
render! { render! {
input { input {
+3 -3
View File
@@ -5,10 +5,10 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let toggled = use_state(cx, || false); let toggled = use_state(|| false);
use_global_shortcut(cx, "ctrl+s", { use_global_shortcut("ctrl+s", {
to_owned![toggled]; to_owned![toggled];
move || toggled.modify(|t| !*t) move || toggled.modify(|t| !*t)
}); });
+2 -2
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let a = 123; let a = 123;
let b = 456; let b = 456;
let c = 789; let c = 789;
@@ -30,7 +30,7 @@ fn Component<'a>(
a: i32, a: i32,
b: i32, b: i32,
c: i32, c: i32,
children: Element<'a>, children: Element,
onclick: EventHandler<'a, ()>, onclick: EventHandler<'a, ()>,
) -> Element { ) -> Element {
render! { render! {
+5 -5
View File
@@ -5,14 +5,14 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let running = dioxus_signals::use_signal(cx, || true); let running = dioxus_signals::use_signal(|| true);
let mut count = dioxus_signals::use_signal(cx, || 0); let mut count = dioxus_signals::use_signal(|| 0);
let saved_values = dioxus_signals::use_signal(cx, || vec![0.to_string()]); let saved_values = dioxus_signals::use_signal(|| vec![0.to_string()]);
// Signals can be used in async functions without an explicit clone since they're 'static and Copy // Signals can be used in async functions without an explicit clone since they're 'static and Copy
// Signals are backed by a runtime that is designed to deeply integrate with Dioxus apps // Signals are backed by a runtime that is designed to deeply integrate with Dioxus apps
use_future!(cx, || async move { use_future!(|| async move {
loop { loop {
if running.value() { if running.value() {
count += 1; count += 1;
+6 -6
View File
@@ -13,7 +13,7 @@ fn main() {
} }
#[component] #[component]
fn App(cx: Scope) -> Element { fn App() -> Element {
render! { render! {
Router::<Route> {} Router::<Route> {}
} }
@@ -38,7 +38,7 @@ enum Route {
} }
#[component] #[component]
fn NavBar(cx: Scope) -> Element { fn NavBar() -> Element {
render! { render! {
h1 { "Your app here" } h1 { "Your app here" }
ul { ul {
@@ -53,19 +53,19 @@ fn NavBar(cx: Scope) -> Element {
} }
#[component] #[component]
fn Home(cx: Scope) -> Element { fn Home() -> Element {
log::debug!("rendering home {:?}", cx.scope_id()); log::debug!("rendering home {:?}", cx.scope_id());
render! { h1 { "Home" } } render! { h1 { "Home" } }
} }
#[component] #[component]
fn BlogList(cx: Scope) -> Element { fn BlogList() -> Element {
log::debug!("rendering blog list {:?}", cx.scope_id()); log::debug!("rendering blog list {:?}", cx.scope_id());
render! { div { "Blog List" } } render! { div { "Blog List" } }
} }
#[component] #[component]
fn BlogPost(cx: Scope, post: String) -> Element { fn BlogPost(post: String) -> Element {
log::debug!("rendering blog post {}", post); log::debug!("rendering blog post {}", post);
render! { render! {
@@ -77,6 +77,6 @@ fn BlogPost(cx: Scope, post: String) -> Element {
} }
#[component] #[component]
fn Oranges(cx: Scope) -> Element { fn Oranges() -> Element {
render!("Oranges are not apples!") render!("Oranges are not apples!")
} }
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx!( cx.render(rsx!(
div { div {
// Use Map directly to lazily pull elements // Use Map directly to lazily pull elements
+3 -3
View File
@@ -13,12 +13,12 @@ enum Route {
} }
#[component] #[component]
fn Homepage(cx: Scope) -> Element { fn Homepage() -> Element {
render! { h1 { "Welcome home" } } render! { h1 { "Welcome home" } }
} }
#[component] #[component]
fn Blog(cx: Scope, id: String) -> Element { fn Blog(id: String) -> Element {
render! { render! {
h1 { "How to make: " } h1 { "How to make: " }
p { "{id}" } p { "{id}" }
@@ -26,7 +26,7 @@ fn Blog(cx: Scope, id: String) -> Element {
} }
#[component] #[component]
fn Nav(cx: Scope) -> Element { fn Nav() -> Element {
render! { render! {
nav { nav {
li { Link { to: Route::Homepage { }, "Go home" } } li { Link { to: Route::Homepage { }, "Go home" } }
+2 -2
View File
@@ -8,7 +8,7 @@ fn main() {
println!("{}", html); println!("{}", html);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
render! { render! {
Component { Component {
width: "10px", width: "10px",
@@ -21,7 +21,7 @@ fn app(cx: Scope) -> Element {
} }
#[component] #[component]
fn Component<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> { fn Component(props: Props -> Element {
render! { render! {
audio { ..cx.props.attributes, "1: {cx.props.extra_data}\n2: {cx.props.extra_data2}" } audio { ..cx.props.attributes, "1: {cx.props.extra_data}\n2: {cx.props.extra_data2}" }
} }
+1 -1
View File
@@ -30,7 +30,7 @@ fn main() {
println!("{file}"); println!("{file}");
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx!( cx.render(rsx!(
div { div {
h1 { "Title" } h1 { "Title" }
+3 -3
View File
@@ -7,10 +7,10 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let count = use_signal(cx, || 10); let count = use_signal(|| 10);
use_future(cx, (), |_| async move { use_future((), |_| async move {
let mut stream = some_stream(); let mut stream = some_stream();
while let Some(second) = stream.next().await { while let Some(second) = stream.next().await {
+3 -3
View File
@@ -31,7 +31,7 @@ struct DogApi {
message: String, message: String,
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div { div {
h1 {"Dogs are very important"} h1 {"Dogs are very important"}
@@ -52,8 +52,8 @@ fn app(cx: Scope) -> Element {
/// This component will re-render when the future has finished /// This component will re-render when the future has finished
/// Suspense is achieved my moving the future into only the component that /// Suspense is achieved my moving the future into only the component that
/// actually renders the data. /// actually renders the data.
fn Doggo(cx: Scope) -> Element { fn Doggo() -> Element {
let fut = use_future(cx, (), |_| async move { let fut = use_future((), |_| async move {
reqwest::get("https://dog.ceo/api/breeds/image/random/") reqwest::get("https://dog.ceo/api/breeds/image/random/")
.await .await
.unwrap() .unwrap()
+3 -3
View File
@@ -6,8 +6,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let val = use_state(cx, || 5); let val = use_state(|| 5);
cx.render(rsx! { cx.render(rsx! {
div { div {
@@ -58,7 +58,7 @@ const UNHELD_COLOR: &str = "#ddd";
// A six-sided die (D6) with dots. // A six-sided die (D6) with dots.
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn Die<'a>(cx: Scope<'a, DieProps<'a>>) -> Element { pub fn Die(props: DieProps -> Element {
let &DieProps { value, keep, .. } = cx.props; let &DieProps { value, keep, .. } = cx.props;
let active_dots = &DOTS_FOR_VALUE[(value - 1) as usize]; let active_dots = &DOTS_FOR_VALUE[(value - 1) as usize];
+1 -1
View File
@@ -1,6 +1,6 @@
use dioxus::prelude::*; use dioxus::prelude::*;
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx!( svg { cx.render(rsx!( svg {
width: "200", width: "200",
height: "250", height: "250",
+3 -3
View File
@@ -11,7 +11,7 @@ fn main() {
dioxus_web::launch(app); dioxus_web::launch(app);
} }
pub fn app(cx: Scope) -> Element { pub fn app() -> Element {
let grey_background = true; let grey_background = true;
cx.render(rsx!( cx.render(rsx!(
div { div {
@@ -78,7 +78,7 @@ pub fn app(cx: Scope) -> Element {
)) ))
} }
pub fn StacksIcon(cx: Scope) -> Element { pub fn StacksIcon() -> Element {
cx.render(rsx!( cx.render(rsx!(
svg { svg {
fill: "none", fill: "none",
@@ -93,7 +93,7 @@ pub fn StacksIcon(cx: Scope) -> Element {
)) ))
} }
pub fn RightArrowIcon(cx: Scope) -> Element { pub fn RightArrowIcon() -> Element {
cx.render(rsx!( cx.render(rsx!(
svg { svg {
fill: "none", fill: "none",
+3 -3
View File
@@ -9,10 +9,10 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let count = use_state(cx, || 0); let count = use_state(|| 0);
use_future(cx, (), move |_| { use_future((), move |_| {
let mut count = count.clone(); let mut count = count.clone();
async move { async move {
loop { loop {
+2 -2
View File
@@ -6,8 +6,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let model = use_state(cx, || String::from("asd")); let model = use_state(|| String::from("asd"));
println!("{model}"); println!("{model}");
+9 -9
View File
@@ -22,8 +22,8 @@ pub struct TodoItem {
} }
pub fn app(cx: Scope<()>) -> Element { pub fn app(cx: Scope<()>) -> Element {
let todos = use_state(cx, im_rc::HashMap::<u32, TodoItem>::default); let todos = use_state(im_rc::HashMap::<u32, TodoItem>::default);
let filter = use_state(cx, || FilterState::All); let filter = use_state(|| FilterState::All);
// Filter the todos based on the filter state // Filter the todos based on the filter state
let mut filtered_todos = todos let mut filtered_todos = todos
@@ -94,9 +94,9 @@ pub struct TodoHeaderProps<'a> {
todos: &'a UseState<im_rc::HashMap<u32, TodoItem>>, todos: &'a UseState<im_rc::HashMap<u32, TodoItem>>,
} }
pub fn TodoHeader<'a>(cx: Scope<'a, TodoHeaderProps<'a>>) -> Element { pub fn TodoHeader(props: TodoHeaderProps -> Element {
let draft = use_state(cx, || "".to_string()); let draft = use_state(|| "".to_string());
let todo_id = use_state(cx, || 0); let todo_id = use_state(|| 0);
cx.render(rsx! { cx.render(rsx! {
header { class: "header", header { class: "header",
@@ -137,8 +137,8 @@ pub struct TodoEntryProps<'a> {
id: u32, id: u32,
} }
pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element { pub fn TodoEntry(props: TodoEntryProps -> Element {
let is_editing = use_state(cx, || false); let is_editing = use_state(|| false);
let todos = cx.props.todos.get(); let todos = cx.props.todos.get();
let todo = &todos[&cx.props.id]; let todo = &todos[&cx.props.id];
@@ -199,7 +199,7 @@ pub struct ListFooterProps<'a> {
filter: &'a UseState<FilterState>, filter: &'a UseState<FilterState>,
} }
pub fn ListFooter<'a>(cx: Scope<'a, ListFooterProps<'a>>) -> Element { pub fn ListFooter(props: ListFooterProps -> Element {
let active_todo_count = cx.props.active_todo_count; let active_todo_count = cx.props.active_todo_count;
let active_todo_text = cx.props.active_todo_text; let active_todo_text = cx.props.active_todo_text;
@@ -245,7 +245,7 @@ pub fn ListFooter<'a>(cx: Scope<'a, ListFooterProps<'a>>) -> Element {
}) })
} }
pub fn PageFooter(cx: Scope) -> Element { pub fn PageFooter() -> Element {
cx.render(rsx! { cx.render(rsx! {
footer { class: "info", footer { class: "info",
p { "Double-click to edit a todo" } p { "Double-click to edit a todo" }
+2 -2
View File
@@ -29,8 +29,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
use_asset_handler(cx, "videos", move |request, responder| { use_asset_handler("videos", move |request, responder| {
// Using dioxus::spawn works, but is slower than a dedicated thread // Using dioxus::spawn works, but is slower than a dedicated thread
tokio::task::spawn(async move { tokio::task::spawn(async move {
let video_file = PathBuf::from(VIDEO_PATH); let video_file = PathBuf::from(VIDEO_PATH);
+1 -1
View File
@@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
web-component { web-component {
"my-prop": "5%", "my-prop": "5%",
+4 -4
View File
@@ -11,16 +11,16 @@ fn main() {
dioxus_desktop::launch_cfg(app, cfg); dioxus_desktop::launch_cfg(app, cfg);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let window = dioxus_desktop::use_window(cx); let window = dioxus_desktop::use_window(cx);
// if you want to make window fullscreen, you need close the resizable. // if you want to make window fullscreen, you need close the resizable.
// window.set_fullscreen(true); // window.set_fullscreen(true);
// window.set_resizable(false); // window.set_resizable(false);
let fullscreen = use_state(cx, || false); let fullscreen = use_state(|| false);
let always_on_top = use_state(cx, || false); let always_on_top = use_state(|| false);
let decorations = use_state(cx, || false); let decorations = use_state(|| false);
cx.render(rsx!( cx.render(rsx!(
link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" } link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" }
+3 -3
View File
@@ -10,10 +10,10 @@ fn main() {
dioxus_desktop::launch_cfg(app, cfg); dioxus_desktop::launch_cfg(app, cfg);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let focused = use_state(cx, || false); let focused = use_state(|| false);
use_wry_event_handler(cx, { use_wry_event_handler({
to_owned![focused]; to_owned![focused];
move |event, _| { move |event, _| {
if let WryEvent::WindowEvent { if let WryEvent::WindowEvent {
+2 -2
View File
@@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let level = use_state(cx, || 1.0); let level = use_state(|| 1.0);
cx.render(rsx! { cx.render(rsx! {
input { input {
+2 -4
View File
@@ -8,10 +8,8 @@ fn main() {
dioxus_desktop::launch(app); dioxus_desktop::launch(app);
} }
fn app(cx: Scope) -> Element { fn app() -> Element {
let contents = use_state(cx, || { let contents = use_state(|| String::from("<script>alert(\"hello world\")</script>"));
String::from("<script>alert(\"hello world\")</script>")
});
cx.render(rsx! { cx.render(rsx! {
div { div {
+2 -2
View File
@@ -55,8 +55,8 @@
Dioxus 是一个可移植的、高性能的、符合人体工程学的框架,使用 Rust 语言构建跨平台的用户界面。 Dioxus 是一个可移植的、高性能的、符合人体工程学的框架,使用 Rust 语言构建跨平台的用户界面。
```rust ```rust
fn app(cx: Scope) -> Element { fn app() -> Element {
let mut count = use_state(cx, || 0); let mut count = use_state(|| 0);
cx.render(rsx! { cx.render(rsx! {
h1 { "High-Five counter: {count}" } h1 { "High-Five counter: {count}" }
+2 -2
View File
@@ -5,8 +5,8 @@ pub fn Explainer<'a>(
cx: Scope<'a>, cx: Scope<'a>,
invert: bool, invert: bool,
title: &'static str, title: &'static str,
content: Element<'a>, content: Element,
flasher: Element<'a>, flasher: Element,
) -> Element { ) -> Element {
// pt-5 sm:pt-24 lg:pt-24 // pt-5 sm:pt-24 lg:pt-24
@@ -1,4 +1,4 @@
fn SaveClipboard(cx: Scope) -> Element { fn SaveClipboard() -> Element {
rsx! { rsx! {
div { class: "relative w-1/2 {align} max-w-md leading-8", div { class: "relative w-1/2 {align} max-w-md leading-8",
h2 { class: "mb-6 text-3xl leading-tight md:text-4xl md:leading-tight lg:text-3xl lg:leading-tight font-heading font-mono font-bold", h2 { class: "mb-6 text-3xl leading-tight md:text-4xl md:leading-tight lg:text-3xl lg:leading-tight font-heading font-mono font-bold",
+1 -1
View File
@@ -1,3 +1,3 @@
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { div { "hello world" } }) cx.render(rsx! { div { "hello world" } })
} }
@@ -1,4 +1,4 @@
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div {"hello world" } div {"hello world" }
}) })
+1 -1
View File
@@ -1,3 +1,3 @@
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { div { "hello world" } }) cx.render(rsx! { div { "hello world" } })
} }
@@ -1,4 +1,4 @@
fn app(cx: Scope) -> Element { fn app() -> Element {
cx.render(rsx! { cx.render(rsx! {
div {"hello world" } div {"hello world" }
}) })
+38 -38
View File
@@ -279,7 +279,7 @@ mod tests {
#[test] #[test]
fn test_no_hooks() { fn test_no_hooks() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
rsx! { rsx! {
p { "Hello World" } p { "Hello World" }
} }
@@ -294,8 +294,8 @@ mod tests {
#[test] #[test]
fn test_hook_correctly_used_inside_component() { fn test_hook_correctly_used_inside_component() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
let count = use_state(cx, || 0); let count = use_state(|| 0);
rsx! { rsx! {
p { "Hello World: {count}" } p { "Hello World: {count}" }
} }
@@ -310,8 +310,8 @@ mod tests {
#[test] #[test]
fn test_hook_correctly_used_inside_hook_fn() { fn test_hook_correctly_used_inside_hook_fn() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn use_thing(cx: Scope) -> UseState<i32> { fn use_thing() -> UseState<i32> {
use_state(cx, || 0) use_state(|| 0)
} }
"#}; "#};
@@ -323,9 +323,9 @@ mod tests {
#[test] #[test]
fn test_hook_correctly_used_inside_hook_closure() { fn test_hook_correctly_used_inside_hook_closure() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
let use_thing = || { let use_thing = || {
use_state(cx, || 0) use_state(|| 0)
}; };
let count = use_thing(); let count = use_thing();
rsx! { rsx! {
@@ -342,9 +342,9 @@ mod tests {
#[test] #[test]
fn test_conditional_hook_if() { fn test_conditional_hook_if() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
if you_are_happy && you_know_it { if you_are_happy && you_know_it {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
println!("clap your {something}") println!("clap your {something}")
} }
} }
@@ -357,7 +357,7 @@ mod tests {
vec![Issue::HookInsideConditional( vec![Issue::HookInsideConditional(
HookInfo::new( HookInfo::new(
Span::new_from_str( Span::new_from_str(
r#"use_state(cx, || "hands")"#, r#"use_state(|| "hands")"#,
LineColumn { line: 3, column: 24 }, LineColumn { line: 3, column: 24 },
), ),
Span::new_from_str( Span::new_from_str(
@@ -368,7 +368,7 @@ mod tests {
), ),
ConditionalInfo::If(IfInfo::new( ConditionalInfo::If(IfInfo::new(
Span::new_from_str( Span::new_from_str(
"if you_are_happy && you_know_it {\n let something = use_state(cx, || \"hands\");\n println!(\"clap your {something}\")\n }", "if you_are_happy && you_know_it {\n let something = use_state(|| \"hands\");\n println!(\"clap your {something}\")\n }",
LineColumn { line: 2, column: 4 }, LineColumn { line: 2, column: 4 },
), ),
Span::new_from_str( Span::new_from_str(
@@ -383,10 +383,10 @@ mod tests {
#[test] #[test]
fn test_conditional_hook_match() { fn test_conditional_hook_match() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
match you_are_happy && you_know_it { match you_are_happy && you_know_it {
true => { true => {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
println!("clap your {something}") println!("clap your {something}")
} }
false => {} false => {}
@@ -400,13 +400,13 @@ mod tests {
report.issues, report.issues,
vec![Issue::HookInsideConditional( vec![Issue::HookInsideConditional(
HookInfo::new( HookInfo::new(
Span::new_from_str(r#"use_state(cx, || "hands")"#, LineColumn { line: 4, column: 28 }), Span::new_from_str(r#"use_state(|| "hands")"#, LineColumn { line: 4, column: 28 }),
Span::new_from_str(r#"use_state"#, LineColumn { line: 4, column: 28 }), Span::new_from_str(r#"use_state"#, LineColumn { line: 4, column: 28 }),
"use_state".to_string() "use_state".to_string()
), ),
ConditionalInfo::Match(MatchInfo::new( ConditionalInfo::Match(MatchInfo::new(
Span::new_from_str( Span::new_from_str(
"match you_are_happy && you_know_it {\n true => {\n let something = use_state(cx, || \"hands\");\n println!(\"clap your {something}\")\n }\n false => {}\n }", "match you_are_happy && you_know_it {\n true => {\n let something = use_state(|| \"hands\");\n println!(\"clap your {something}\")\n }\n false => {}\n }",
LineColumn { line: 2, column: 4 }, LineColumn { line: 2, column: 4 },
), ),
Span::new_from_str("match you_are_happy && you_know_it", LineColumn { line: 2, column: 4 }) Span::new_from_str("match you_are_happy && you_know_it", LineColumn { line: 2, column: 4 })
@@ -418,9 +418,9 @@ mod tests {
#[test] #[test]
fn test_for_loop_hook() { fn test_for_loop_hook() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
for _name in &names { for _name in &names {
let is_selected = use_state(cx, || false); let is_selected = use_state(|| false);
println!("selected: {is_selected}"); println!("selected: {is_selected}");
} }
} }
@@ -433,7 +433,7 @@ mod tests {
vec![Issue::HookInsideLoop( vec![Issue::HookInsideLoop(
HookInfo::new( HookInfo::new(
Span::new_from_str( Span::new_from_str(
"use_state(cx, || false)", "use_state(|| false)",
LineColumn { line: 3, column: 26 }, LineColumn { line: 3, column: 26 },
), ),
Span::new_from_str( Span::new_from_str(
@@ -444,7 +444,7 @@ mod tests {
), ),
AnyLoopInfo::For(ForInfo::new( AnyLoopInfo::For(ForInfo::new(
Span::new_from_str( Span::new_from_str(
"for _name in &names {\n let is_selected = use_state(cx, || false);\n println!(\"selected: {is_selected}\");\n }", "for _name in &names {\n let is_selected = use_state(|| false);\n println!(\"selected: {is_selected}\");\n }",
LineColumn { line: 2, column: 4 }, LineColumn { line: 2, column: 4 },
), ),
Span::new_from_str( Span::new_from_str(
@@ -459,9 +459,9 @@ mod tests {
#[test] #[test]
fn test_while_loop_hook() { fn test_while_loop_hook() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
while true { while true {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
println!("clap your {something}") println!("clap your {something}")
} }
} }
@@ -474,7 +474,7 @@ mod tests {
vec![Issue::HookInsideLoop( vec![Issue::HookInsideLoop(
HookInfo::new( HookInfo::new(
Span::new_from_str( Span::new_from_str(
r#"use_state(cx, || "hands")"#, r#"use_state(|| "hands")"#,
LineColumn { line: 3, column: 24 }, LineColumn { line: 3, column: 24 },
), ),
Span::new_from_str( Span::new_from_str(
@@ -485,7 +485,7 @@ mod tests {
), ),
AnyLoopInfo::While(WhileInfo::new( AnyLoopInfo::While(WhileInfo::new(
Span::new_from_str( Span::new_from_str(
"while true {\n let something = use_state(cx, || \"hands\");\n println!(\"clap your {something}\")\n }", "while true {\n let something = use_state(|| \"hands\");\n println!(\"clap your {something}\")\n }",
LineColumn { line: 2, column: 4 }, LineColumn { line: 2, column: 4 },
), ),
Span::new_from_str( Span::new_from_str(
@@ -500,9 +500,9 @@ mod tests {
#[test] #[test]
fn test_loop_hook() { fn test_loop_hook() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
loop { loop {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
println!("clap your {something}") println!("clap your {something}")
} }
} }
@@ -515,7 +515,7 @@ mod tests {
vec![Issue::HookInsideLoop( vec![Issue::HookInsideLoop(
HookInfo::new( HookInfo::new(
Span::new_from_str( Span::new_from_str(
r#"use_state(cx, || "hands")"#, r#"use_state(|| "hands")"#,
LineColumn { line: 3, column: 24 }, LineColumn { line: 3, column: 24 },
), ),
Span::new_from_str( Span::new_from_str(
@@ -525,7 +525,7 @@ mod tests {
"use_state".to_string() "use_state".to_string()
), ),
AnyLoopInfo::Loop(LoopInfo::new(Span::new_from_str( AnyLoopInfo::Loop(LoopInfo::new(Span::new_from_str(
"loop {\n let something = use_state(cx, || \"hands\");\n println!(\"clap your {something}\")\n }", "loop {\n let something = use_state(|| \"hands\");\n println!(\"clap your {something}\")\n }",
LineColumn { line: 2, column: 4 }, LineColumn { line: 2, column: 4 },
))) )))
)], )],
@@ -535,8 +535,8 @@ mod tests {
#[test] #[test]
fn test_conditional_okay() { fn test_conditional_okay() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
if you_are_happy && you_know_it { if you_are_happy && you_know_it {
println!("clap your {something}") println!("clap your {something}")
} }
@@ -551,9 +551,9 @@ mod tests {
#[test] #[test]
fn test_closure_hook() { fn test_closure_hook() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
let _a = || { let _a = || {
let b = use_state(cx, || 0); let b = use_state(|| 0);
b.get() b.get()
}; };
} }
@@ -566,7 +566,7 @@ mod tests {
vec![Issue::HookInsideClosure( vec![Issue::HookInsideClosure(
HookInfo::new( HookInfo::new(
Span::new_from_str( Span::new_from_str(
"use_state(cx, || 0)", "use_state(|| 0)",
LineColumn { LineColumn {
line: 3, line: 3,
column: 16 column: 16
@@ -582,7 +582,7 @@ mod tests {
"use_state".to_string() "use_state".to_string()
), ),
ClosureInfo::new(Span::new_from_str( ClosureInfo::new(Span::new_from_str(
"|| {\n let b = use_state(cx, || 0);\n b.get()\n }", "|| {\n let b = use_state(|| 0);\n b.get()\n }",
LineColumn { LineColumn {
line: 2, line: 2,
column: 13 column: 13
@@ -595,8 +595,8 @@ mod tests {
#[test] #[test]
fn test_hook_outside_component() { fn test_hook_outside_component() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn not_component_or_hook(cx: Scope) { fn not_component_or_hook() {
let _a = use_state(cx, || 0); let _a = use_state(|| 0);
} }
"#}; "#};
@@ -606,7 +606,7 @@ mod tests {
report.issues, report.issues,
vec![Issue::HookOutsideComponent(HookInfo::new( vec![Issue::HookOutsideComponent(HookInfo::new(
Span::new_from_str( Span::new_from_str(
"use_state(cx, || 0)", "use_state(|| 0)",
LineColumn { LineColumn {
line: 2, line: 2,
column: 13 column: 13
@@ -627,8 +627,8 @@ mod tests {
#[test] #[test]
fn test_hook_inside_hook() { fn test_hook_inside_hook() {
let contents = indoc! {r#" let contents = indoc! {r#"
fn use_thing(cx: Scope) { fn use_thing() {
let _a = use_state(cx, || 0); let _a = use_state(|| 0);
} }
"#}; "#};
+21 -21
View File
@@ -230,9 +230,9 @@ mod tests {
let issue_report = check_file( let issue_report = check_file(
"src/main.rs".into(), "src/main.rs".into(),
indoc! {r#" indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
if you_are_happy && you_know_it { if you_are_happy && you_know_it {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
println!("clap your {something}") println!("clap your {something}")
} }
} }
@@ -243,7 +243,7 @@ mod tests {
error: hook called conditionally: `use_state` (inside `if`) error: hook called conditionally: `use_state` (inside `if`)
--> src/main.rs:3:25 --> src/main.rs:3:25
| |
3 | let something = use_state(cx, || "hands"); 3 | let something = use_state(|| "hands");
| ^^^^^^^^^ | ^^^^^^^^^
| |
= note: `if you_are_happy && you_know_it { … }` is the conditional = note: `if you_are_happy && you_know_it { … }` is the conditional
@@ -258,10 +258,10 @@ mod tests {
let issue_report = check_file( let issue_report = check_file(
"src/main.rs".into(), "src/main.rs".into(),
indoc! {r#" indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
match you_are_happy && you_know_it { match you_are_happy && you_know_it {
true => { true => {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
println!("clap your {something}") println!("clap your {something}")
} }
_ => {} _ => {}
@@ -274,7 +274,7 @@ mod tests {
error: hook called conditionally: `use_state` (inside `match`) error: hook called conditionally: `use_state` (inside `match`)
--> src/main.rs:4:29 --> src/main.rs:4:29
| |
4 | let something = use_state(cx, || "hands"); 4 | let something = use_state(|| "hands");
| ^^^^^^^^^ | ^^^^^^^^^
| |
= note: `match you_are_happy && you_know_it { … }` is the conditional = note: `match you_are_happy && you_know_it { … }` is the conditional
@@ -289,9 +289,9 @@ mod tests {
let issue_report = check_file( let issue_report = check_file(
"src/main.rs".into(), "src/main.rs".into(),
indoc! {r#" indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
for i in 0..10 { for i in 0..10 {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
println!("clap your {something}") println!("clap your {something}")
} }
} }
@@ -302,7 +302,7 @@ mod tests {
error: hook called in a loop: `use_state` (inside `for` loop) error: hook called in a loop: `use_state` (inside `for` loop)
--> src/main.rs:3:25 --> src/main.rs:3:25
| |
3 | let something = use_state(cx, || "hands"); 3 | let something = use_state(|| "hands");
| ^^^^^^^^^ | ^^^^^^^^^
| |
= note: `for i in 0..10 { … }` is the loop = note: `for i in 0..10 { … }` is the loop
@@ -317,9 +317,9 @@ mod tests {
let issue_report = check_file( let issue_report = check_file(
"src/main.rs".into(), "src/main.rs".into(),
indoc! {r#" indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
while check_thing() { while check_thing() {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
println!("clap your {something}") println!("clap your {something}")
} }
} }
@@ -330,7 +330,7 @@ mod tests {
error: hook called in a loop: `use_state` (inside `while` loop) error: hook called in a loop: `use_state` (inside `while` loop)
--> src/main.rs:3:25 --> src/main.rs:3:25
| |
3 | let something = use_state(cx, || "hands"); 3 | let something = use_state(|| "hands");
| ^^^^^^^^^ | ^^^^^^^^^
| |
= note: `while check_thing() { … }` is the loop = note: `while check_thing() { … }` is the loop
@@ -345,9 +345,9 @@ mod tests {
let issue_report = check_file( let issue_report = check_file(
"src/main.rs".into(), "src/main.rs".into(),
indoc! {r#" indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
loop { loop {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
println!("clap your {something}") println!("clap your {something}")
} }
} }
@@ -358,7 +358,7 @@ mod tests {
error: hook called in a loop: `use_state` (inside `loop`) error: hook called in a loop: `use_state` (inside `loop`)
--> src/main.rs:3:25 --> src/main.rs:3:25
| |
3 | let something = use_state(cx, || "hands"); 3 | let something = use_state(|| "hands");
| ^^^^^^^^^ | ^^^^^^^^^
| |
= note: `loop { … }` is the loop = note: `loop { … }` is the loop
@@ -373,9 +373,9 @@ mod tests {
let issue_report = check_file( let issue_report = check_file(
"src/main.rs".into(), "src/main.rs".into(),
indoc! {r#" indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
let something = || { let something = || {
let something = use_state(cx, || "hands"); let something = use_state(|| "hands");
println!("clap your {something}") println!("clap your {something}")
}; };
} }
@@ -386,7 +386,7 @@ mod tests {
error: hook called in a closure: `use_state` error: hook called in a closure: `use_state`
--> src/main.rs:3:25 --> src/main.rs:3:25
| |
3 | let something = use_state(cx, || "hands"); 3 | let something = use_state(|| "hands");
| ^^^^^^^^^ | ^^^^^^^^^
"#}; "#};
@@ -399,9 +399,9 @@ mod tests {
let issue_report = check_file( let issue_report = check_file(
"src/main.rs".into(), "src/main.rs".into(),
indoc! {r#" indoc! {r#"
fn App(cx: Scope) -> Element { fn App() -> Element {
if you_are_happy && you_know_it { if you_are_happy && you_know_it {
let something = use_state(cx, || { let something = use_state(|| {
"hands" "hands"
}); });
println!("clap your {something}") println!("clap your {something}")
@@ -414,7 +414,7 @@ mod tests {
error: hook called conditionally: `use_state` (inside `if`) error: hook called conditionally: `use_state` (inside `if`)
--> src/main.rs:3:25 --> src/main.rs:3:25
| |
3 | let something = use_state(cx, || { 3 | let something = use_state(|| {
| ^^^^^^^^^ | ^^^^^^^^^
4 | "hands" 4 | "hands"
5 | }); 5 | });
+1 -1
View File
@@ -3,7 +3,7 @@
pub struct HookInfo { pub struct HookInfo {
/// The name of the hook, e.g. `use_state`. /// The name of the hook, e.g. `use_state`.
pub name: String, pub name: String,
/// The span of the hook, e.g. `use_state(cx, || 0)`. /// The span of the hook, e.g. `use_state(|| 0)`.
pub span: Span, pub span: Span,
/// The span of the name, e.g. `use_state`. /// The span of the name, e.g. `use_state`.
pub name_span: Span, pub name_span: Span,
+2 -2
View File
@@ -71,7 +71,7 @@ fn write_callbody_with_icon_section(mut callbody: CallBody) -> String {
} }
fn write_component_body(raw: String) -> String { fn write_component_body(raw: String) -> String {
let mut out = String::from("fn component(cx: Scope) -> Element {\n cx.render(rsx! {"); let mut out = String::from("fn component() -> Element {\n cx.render(rsx! {");
indent_and_write(&raw, 1, &mut out); indent_and_write(&raw, 1, &mut out);
out.push_str(" })\n}"); out.push_str(" })\n}");
out out
@@ -84,7 +84,7 @@ fn write_svg_section(out: &mut String, svgs: Vec<BodyNode>) {
let raw = dioxus_autofmt::write_block_out(CallBody { roots: vec![icon] }).unwrap(); let raw = dioxus_autofmt::write_block_out(CallBody { roots: vec![icon] }).unwrap();
out.push_str("\n\n pub fn icon_"); out.push_str("\n\n pub fn icon_");
out.push_str(&idx.to_string()); out.push_str(&idx.to_string());
out.push_str("(cx: Scope) -> Element {\n cx.render(rsx! {"); out.push_str("() -> Element {\n cx.render(rsx! {");
indent_and_write(&raw, 2, out); indent_and_write(&raw, 2, out);
out.push_str(" })\n }"); out.push_str(" })\n }");
} }
+2 -2
View File
@@ -36,7 +36,7 @@ async fn setup_file_watcher<F: Fn() -> Result<BuildResult> + Send + 'static>(
if let Some(hot_reload) = &hot_reload { if let Some(hot_reload) = &hot_reload {
// find changes to the rsx in the file // find changes to the rsx in the file
let mut rsx_file_map = hot_reload.file_map.lock().unwrap(); let mut rsx_file_map = hot_reload.file_map.lock().unwrap();
let mut messages: Vec<Template<'static>> = Vec::new(); let mut messages: Vec<Template> = Vec::new();
// In hot reload mode, we only need to rebuild if non-rsx code is changed // In hot reload mode, we only need to rebuild if non-rsx code is changed
needs_full_rebuild = false; needs_full_rebuild = false;
@@ -143,6 +143,6 @@ pub(crate) trait Platform {
#[derive(Clone)] #[derive(Clone)]
pub struct HotReloadState { pub struct HotReloadState {
pub messages: broadcast::Sender<Template<'static>>, pub messages: broadcast::Sender<Template>,
pub file_map: Arc<Mutex<FileMap<HtmlCtx>>>, pub file_map: Arc<Mutex<FileMap<HtmlCtx>>>,
} }
@@ -66,11 +66,11 @@
//! use dioxus::prelude::*; //! use dioxus::prelude::*;
//! //!
//! #[name_changer(CoolName)] //! #[name_changer(CoolName)]
//! pub fn LameName(cx: Scope) -> Element { //! pub fn LameName() -> Element {
//! render! { "I want a cool name!" } //! render! { "I want a cool name!" }
//! } //! }
//! //!
//! pub fn App(cx: Scope) -> Element { //! pub fn App() -> Element {
//! render! { CoolName {} } // Renders: "I want a cool name!" //! render! { CoolName {} } // Renders: "I want a cool name!"
//! } //! }
//! ``` //! ```
+7 -7
View File
@@ -65,7 +65,7 @@ pub fn render(s: TokenStream) -> TokenStream {
/// # Example /// # Example
/// ```rust,ignore /// ```rust,ignore
/// #[inline_props] /// #[inline_props]
/// fn app(cx: Scope, bob: String) -> Element { /// fn app(bob: String) -> Element {
/// cx.render(rsx!("hello, {bob}")) /// cx.render(rsx!("hello, {bob}"))
/// } /// }
/// ///
@@ -128,17 +128,17 @@ pub(crate) const COMPONENT_ARG_CASE_CHECK_OFF: &str = "no_case_check";
/// * Without props: /// * Without props:
/// ```rust,ignore /// ```rust,ignore
/// #[component] /// #[component]
/// fn GreetBob(cx: Scope) -> Element { /// fn GreetBob() -> Element {
/// render! { "hello, bob" } /// render! { "hello, bob" }
/// } /// }
/// ///
/// // is equivalent to /// // is equivalent to
/// ///
/// #[allow(non_snake_case)] /// #[allow(non_snake_case)]
/// fn GreetBob(cx: Scope) -> Element { /// fn GreetBob() -> Element {
/// #[warn(non_snake_case)] /// #[warn(non_snake_case)]
/// #[inline(always)] /// #[inline(always)]
/// fn __dx_inner_comp(cx: Scope) -> Element { /// fn __dx_inner_comp() -> Element {
/// render! { "hello, bob" } /// render! { "hello, bob" }
/// } /// }
/// // There's no function call overhead since __dx_inner_comp has the #[inline(always)] attribute, /// // There's no function call overhead since __dx_inner_comp has the #[inline(always)] attribute,
@@ -149,7 +149,7 @@ pub(crate) const COMPONENT_ARG_CASE_CHECK_OFF: &str = "no_case_check";
/// * With props: /// * With props:
/// ```rust,ignore /// ```rust,ignore
/// #[component(no_case_check)] /// #[component(no_case_check)]
/// fn GreetPerson(cx: Scope, person: String) -> Element { /// fn GreetPerson(person: String) -> Element {
/// render! { "hello, {person}" } /// render! { "hello, {person}" }
/// } /// }
/// ///
@@ -162,10 +162,10 @@ pub(crate) const COMPONENT_ARG_CASE_CHECK_OFF: &str = "no_case_check";
/// } /// }
/// ///
/// #[allow(non_snake_case)] /// #[allow(non_snake_case)]
/// fn GreetPerson<'a>(cx: Scope<'a, GreetPersonProps>) -> Element { /// fn GreetPerson(props: GreetPersonProps>) -> Element {
/// #[warn(non_snake_case)] /// #[warn(non_snake_case)]
/// #[inline(always)] /// #[inline(always)]
/// fn __dx_inner_comp<'a>(cx: Scope<'a, GreetPersonProps>e) -> Element { /// fn __dx_inner_comp(props: GreetPersonProps>e) -> Element {
/// let GreetPersonProps { person } = &cx.props; /// let GreetPersonProps { person } = &cx.props;
/// { /// {
/// render! { "hello, {person}" } /// render! { "hello, {person}" }
+4
View File
@@ -99,6 +99,10 @@ pub fn once<State: Clone + 'static>(initializer: impl FnOnce() -> State) -> Stat
with_current_scope(|cx| cx.use_hook(initializer)).expect("to be in a dioxus runtime") with_current_scope(|cx| cx.use_hook(initializer)).expect("to be in a dioxus runtime")
} }
pub fn use_hook<State: Clone + 'static>(initializer: impl FnOnce() -> State) -> State {
once(initializer)
}
/// Get the current render since the inception of this component /// Get the current render since the inception of this component
/// ///
/// This can be used as a helpful diagnostic when debugging hooks/renders, etc /// This can be used as a helpful diagnostic when debugging hooks/renders, etc
+1 -1
View File
@@ -87,7 +87,7 @@ pub mod prelude {
consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, generation, consume_context, consume_context_from_scope, current_scope_id, fc_to_builder, generation,
has_context, needs_update, once, parent_scope, provide_context, provide_root_context, has_context, needs_update, once, parent_scope, provide_context, provide_root_context,
push_future, remove_future, schedule_update, schedule_update_any, spawn, spawn_forever, push_future, remove_future, schedule_update, schedule_update_any, spawn, spawn_forever,
suspend, use_error_boundary, AnyValue, Component, Element, ErrorBoundary, Event, suspend, use_error_boundary, use_hook, AnyValue, Component, Element, ErrorBoundary, Event,
EventHandler, Fragment, IntoAttributeValue, IntoDynNode, Properties, Runtime, RuntimeGuard, EventHandler, Fragment, IntoAttributeValue, IntoDynNode, Properties, Runtime, RuntimeGuard,
ScopeId, Task, Template, TemplateAttribute, TemplateNode, Throw, VNode, VNodeInner, ScopeId, Task, Template, TemplateAttribute, TemplateNode, Throw, VNode, VNodeInner,
VirtualDom, VirtualDom,
+7 -4
View File
@@ -1,6 +1,9 @@
use crate::any_props::{BoxedAnyProps, VProps}; use crate::innerlude::{ElementRef, EventHandler, MountId};
use crate::innerlude::{ElementRef, EventHandler, MountId, ScopeState};
use crate::properties::ComponentFunction; use crate::properties::ComponentFunction;
use crate::{
any_props::{BoxedAnyProps, VProps},
innerlude::ScopeState,
};
use crate::{arena::ElementId, Element, Event}; use crate::{arena::ElementId, Element, Event};
use crate::{Properties, VirtualDom}; use crate::{Properties, VirtualDom};
use std::ops::Deref; use std::ops::Deref;
@@ -16,7 +19,7 @@ pub type TemplateId = &'static str;
/// The actual state of the component's most recent computation /// The actual state of the component's most recent computation
/// ///
/// Because Dioxus accepts components in the form of `async fn(Scope) -> Result<VNode>`, we need to support both /// Because Dioxus accepts components in the form of `async fn() -> Result<VNode>`, we need to support both
/// sync and async versions. /// sync and async versions.
/// ///
/// Dioxus will do its best to immediately resolve any async components into a regular Element, but as an implementor /// Dioxus will do its best to immediately resolve any async components into a regular Element, but as an implementor
@@ -457,7 +460,7 @@ impl VComponent {
/// ///
/// ```rust, ignore /// ```rust, ignore
/// // Without explicit props /// // Without explicit props
/// fn(Scope) -> Element; /// fn() -> Element;
/// async fn(Scope<'_>) -> Element; /// async fn(Scope<'_>) -> Element;
/// ///
/// // With explicit props /// // With explicit props
+2 -2
View File
@@ -1,9 +1,9 @@
use crate::{ use crate::{
any_props::{AnyProps, BoxedAnyProps}, any_props::{AnyProps, BoxedAnyProps},
innerlude::DirtyScope, innerlude::{DirtyScope, ScopeState},
nodes::RenderReturn, nodes::RenderReturn,
scope_context::ScopeContext, scope_context::ScopeContext,
scopes::{ScopeId, ScopeState}, scopes::ScopeId,
virtual_dom::VirtualDom, virtual_dom::VirtualDom,
}; };
+1 -1
View File
@@ -254,7 +254,7 @@ impl ScopeContext {
/// use dioxus_core::ScopeState; /// use dioxus_core::ScopeState;
/// ///
/// // prints a greeting on the initial render /// // prints a greeting on the initial render
/// pub fn use_hello_world(cx: &ScopeState) { /// pub fn use_hello_world() {
/// cx.use_hook(|| println!("Hello, world!")); /// cx.use_hook(|| println!("Hello, world!"));
/// } /// }
/// ``` /// ```
+3 -3
View File
@@ -6,13 +6,13 @@ use crate::{
any_props::{BoxedAnyProps, VProps}, any_props::{BoxedAnyProps, VProps},
arena::ElementId, arena::ElementId,
innerlude::{ innerlude::{
DirtyScope, ElementRef, ErrorBoundary, NoOpMutations, Scheduler, SchedulerMsg, VNodeMount, DirtyScope, ElementRef, ErrorBoundary, NoOpMutations, Scheduler, SchedulerMsg, ScopeState,
WriteMutations, VNodeMount, WriteMutations,
}, },
nodes::RenderReturn, nodes::RenderReturn,
nodes::{Template, TemplateId}, nodes::{Template, TemplateId},
runtime::{Runtime, RuntimeGuard}, runtime::{Runtime, RuntimeGuard},
scopes::{ScopeId, ScopeState}, scopes::ScopeId,
AttributeValue, Element, Event, MutationsVec, AttributeValue, Element, Event, MutationsVec,
}; };
use futures_util::{pin_mut, StreamExt}; use futures_util::{pin_mut, StreamExt};
+3 -3
View File
@@ -1,8 +1,8 @@
use dioxus::prelude::*; use dioxus::prelude::*;
fn app(cx: Scope) -> Element { fn app() -> Element {
let state = use_state(cx, || 0); let state = use_state(|| 0);
use_future(cx, (), |_| { use_future((), |_| {
to_owned![state]; to_owned![state];
async move { async move {
loop { loop {
Loaded 100 of 226 files, more files were not shown because too many files have changed in this diff. Show more