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

This commit is contained in:
Jonathan Kelley 2024-01-13 20:51:37 -08:00
parent 4c6e515da4
commit fae0b08e61
No known key found for this signature in database
GPG key ID: 1FBB50F7EB0A08BE
226 changed files with 1057 additions and 1482 deletions

259
Cargo.lock generated
View file

@ -212,12 +212,6 @@ version = "0.12.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344"
[[package]]
name = "anymap"
version = "1.0.0-beta.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f1f8f5a6f3d50d89e3797d7593a50f96bb2aaa20ca0cc7be1fb673232c91d72"
[[package]]
name = "anymap2"
version = "0.13.0"
@ -1396,12 +1390,6 @@ dependencies = [
"toml 0.8.2",
]
[[package]]
name = "cassowary"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df8670b8c7b9dae1793364eafadf7239c40d669904660c5960d74cfd80b46a53"
[[package]]
name = "cast"
version = "0.3.0"
@ -2001,47 +1989,6 @@ version = "0.8.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "cruet"
version = "0.14.0"
@ -2621,7 +2568,6 @@ dependencies = [
"dioxus-signals",
"dioxus-ssr",
"env_logger",
"fermi",
"futures-util",
"http-range",
"im-rc",
@ -2653,7 +2599,7 @@ dependencies = [
name = "dioxus-fullstack"
version = "0.4.3"
dependencies = [
"anymap 0.12.1",
"anymap",
"async-trait",
"axum 0.6.20",
"base64 0.21.7",
@ -2817,40 +2763,6 @@ dependencies = [
"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]]
name = "dioxus-playwright-fullstack-test"
version = "0.1.0"
@ -2997,24 +2909,6 @@ dependencies = [
"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]]
name = "dioxus-web"
version = "0.4.3"
@ -4651,12 +4545,6 @@ dependencies = [
"system-deps",
]
[[package]]
name = "grid"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eec1c01eb1de97451ee0d60de7d81cf1e72aabefb021616027f3d1c3ec1c723c"
[[package]]
name = "group"
version = "0.13.0"
@ -5544,15 +5432,6 @@ dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b1c173a5686ce8bfa551b3563d0c2170bf24ca44da99c7ca4bfdab5418c3fe57"
dependencies = [
"either",
]
[[package]]
name = "itertools"
version = "0.12.0"
@ -6070,15 +5949,6 @@ dependencies = [
"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]]
name = "lru-cache"
version = "0.1.2"
@ -7567,28 +7437,6 @@ version = "0.3.28"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "platforms"
version = "3.3.0"
@ -8043,24 +7891,6 @@ dependencies = [
"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]]
name = "rav1e"
version = "0.6.6"
@ -9420,50 +9250,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "signal-hook-registry"
version = "1.4.1"
@ -9571,15 +9357,6 @@ dependencies = [
"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]]
name = "smallbox"
version = "0.8.2"
@ -10010,28 +9787,6 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "subprocess"
version = "0.2.9"
@ -10132,18 +9887,6 @@ dependencies = [
"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]]
name = "tao"
version = "0.24.0"

View file

@ -17,15 +17,15 @@ members = [
"packages/desktop",
"packages/mobile",
"packages/interpreter",
"packages/fermi",
# "packages/fermi",
"packages/liveview",
"packages/autofmt",
"packages/check",
"packages/rsx",
"packages/dioxus-tui",
"packages/rink",
"packages/native-core",
"packages/native-core-macro",
# "packages/dioxus-tui",
# "packages/rink",
# "packages/native-core",
# "packages/native-core-macro",
"packages/rsx-rosetta",
"packages/generational-box",
"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-mobile = { path = "packages/mobile", 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-autofmt = { path = "packages/autofmt", version = "0.4.0" }
dioxus-check = { path = "packages/check", version = "0.4.0" }
dioxus-rsx = { path = "packages/rsx", version = "0.4.0" }
dioxus-tui = { path = "packages/dioxus-tui", 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-macro = { path = "packages/native-core-macro", version = "0.4.0" }
# dioxus-tui = { path = "packages/dioxus-tui", 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-macro = { path = "packages/native-core-macro", version = "0.4.0" }
rsx-rosetta = { path = "packages/rsx-rosetta", version = "0.4.0" }
dioxus-signals = { path = "packages/signals" }
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-router = { workspace = true }
dioxus-signals = { workspace = true }
fermi = { workspace = true }
# fermi = { workspace = true }
futures-util = "0.3.21"
log = "0.4.14"
num-format = "0.4.0"

View file

@ -55,8 +55,8 @@
Dioxus is a portable, performant, and ergonomic framework for building cross-platform user interfaces in Rust.
```rust
fn app(cx: Scope) -> Element {
let mut count = use_state(cx, || 0);
fn app() -> Element {
let mut count = use_state(|| 0);
cx.render(rsx! {
h1 { "High-Five counter: {count}" }

View file

@ -8,7 +8,7 @@ fn main() {
dioxus_web::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! (
div {
style: "text-align: center;",

View file

@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
align_content: "a",

View file

@ -40,8 +40,8 @@ const RECT_STYLE: &str = r#"
text-aligh: center;
"#;
fn app(cx: Scope) -> Element {
let events = use_ref(cx, std::collections::VecDeque::new);
fn app() -> Element {
let events = use_ref(std::collections::VecDeque::new);
let log_event = move |event: Event| {
let mut events = events.write();

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

View file

@ -18,8 +18,8 @@ fn main() {
dioxus_desktop::launch_cfg(app, config);
}
fn app(cx: Scope) -> Element {
let val = use_state(cx, || String::from("0"));
fn app() -> Element {
let val = use_state(|| String::from("0"));
let input_digit = move |num: u8| {
if val.get() == "0" {

View file

@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let login = use_callback!(cx, move |_| async move {
fn app() -> Element {
let login = use_callback!(move |_| async move {
let res = reqwest::get("https://dog.ceo/api/breeds/list/all")
.await
.unwrap()

View file

@ -5,10 +5,10 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let mut count = use_signal(cx, || 0);
fn app() -> Element {
let mut count = use_signal(|| 0);
use_future!(cx, || async move {
use_future!(|| async move {
loop {
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
count += 1;

View file

@ -7,10 +7,10 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let emails_sent = use_ref(cx, Vec::new);
fn app() -> Element {
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];
async move {
while let Some(message) = rx.next().await {
@ -48,7 +48,7 @@ struct ComposeProps {
}
fn compose(cx: Scope<ComposeProps>) -> Element {
let user_input = use_state(cx, String::new);
let user_input = use_state(String::new);
cx.render(rsx! {
div {

View file

@ -6,11 +6,11 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let elements: &UseRef<Vec<Rc<MountedData>>> = use_ref(cx, Vec::new);
let running = use_state(cx, || true);
fn app() -> Element {
let elements: &UseRef<Vec<Rc<MountedData>>> = use_ref(Vec::new);
let running = use_state(|| true);
use_future!(cx, |(elements, running)| async move {
use_future!(|(elements, running)| async move {
let mut focused = 0;
if *running.current() {
loop {

View file

@ -7,8 +7,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let counters = use_state(cx, || vec![0, 0, 0]);
fn app() -> Element {
let counters = use_state(|| vec![0, 0, 0]);
let sum: usize = counters.iter().copied().sum();
render! {

View file

@ -27,8 +27,8 @@ pub struct Client {
type ClientContext = Vec<Client>;
#[component]
fn App(cx: Scope) -> Element {
use_shared_state_provider::<ClientContext>(cx, Default::default);
fn App() -> Element {
use_shared_state_provider::<ClientContext>(Default::default);
render! {
link {
@ -53,8 +53,8 @@ fn App(cx: Scope) -> Element {
}
#[component]
fn ClientList(cx: Scope) -> Element {
let clients = use_shared_state::<ClientContext>(cx).unwrap();
fn ClientList() -> Element {
let clients = use_shared_state::<ClientContext>().unwrap();
cx.render(rsx! {
h2 { "List of Clients" }
@ -75,11 +75,11 @@ fn ClientList(cx: Scope) -> Element {
}
#[component]
fn ClientAdd(cx: Scope) -> Element {
let clients = use_shared_state::<ClientContext>(cx).unwrap();
let first_name = use_state(cx, String::new);
let last_name = use_state(cx, String::new);
let description = use_state(cx, String::new);
fn ClientAdd() -> Element {
let clients = use_shared_state::<ClientContext>().unwrap();
let first_name = use_state(String::new);
let last_name = use_state(String::new);
let description = use_state(String::new);
cx.render(rsx! {
h2 { "Add new Client" }
@ -142,8 +142,8 @@ fn ClientAdd(cx: Scope) -> Element {
}
#[component]
fn Settings(cx: Scope) -> Element {
let clients = use_shared_state::<ClientContext>(cx).unwrap();
fn Settings() -> Element {
let clients = use_shared_state::<ClientContext>().unwrap();
cx.render(rsx! {
h2 { "Settings" }

View file

@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
p {

View file

@ -31,7 +31,7 @@ fn main() {
);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
h1 {"hello world!"}

View file

@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let disabled = use_state(cx, || false);
fn app() -> Element {
let disabled = use_state(|| false);
cx.render(rsx! {
div {

View file

@ -12,9 +12,9 @@ struct ListBreeds {
#[component]
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")
.await
.unwrap()
@ -51,8 +51,8 @@ struct DogApi {
}
#[component]
fn BreedPic(cx: Scope, breed: String) -> Element {
let fut = use_future!(cx, |breed| async move {
fn BreedPic(breed: String) -> Element {
let fut = use_future!(|breed| async move {
reqwest::get(format!("https://dog.ceo/api/breed/{breed}/images/random"))
.await
.unwrap()

View file

@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
let count = if cx.generation() % 2 == 0 { 10 } else { 0 };
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);
render! {
div{}

View file

@ -5,8 +5,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
use_asset_handler(cx, "logos", |request, response| {
fn app() -> Element {
use_asset_handler("logos", |request, response| {
// 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

View file

@ -5,7 +5,7 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
cx.render(rsx! {
ErrorBoundary {
handle_error: |error: CapturedError| rsx! {"Found error {error}"},
@ -17,7 +17,7 @@ fn App(cx: Scope) -> Element {
}
#[component]
fn DemoC(cx: Scope, x: i32) -> Element {
fn DemoC(x: i32) -> Element {
let result = Err("Error");
result.throw()?;

View file

@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let future = use_future(cx, (), |_| async move {
fn app() -> Element {
let future = use_future((), |_| async move {
let eval = eval(
r#"
dioxus.send("Hi from JS!");

View file

@ -9,9 +9,9 @@ fn main() {
static NAME: Atom<String> = Atom(|_| "world".to_string());
fn app(cx: Scope) -> Element {
fn app() -> Element {
use_init_atom_root(cx);
let name = use_read(cx, &NAME);
let name = use_read(&NAME);
cx.render(rsx! {
div { "hello {name}!" }
@ -20,8 +20,8 @@ fn app(cx: Scope) -> Element {
})
}
fn Child(cx: Scope) -> Element {
let set_name = use_set(cx, &NAME);
fn Child() -> Element {
let set_name = use_set(&NAME);
cx.render(rsx! {
button {
@ -33,8 +33,8 @@ fn Child(cx: Scope) -> Element {
static NAMES: AtomRef<Vec<String>> = AtomRef(|_| vec!["world".to_string()]);
fn ChildWithRef(cx: Scope) -> Element {
let names = use_atom_ref(cx, &NAMES);
fn ChildWithRef() -> Element {
let names = use_atom_ref(&NAMES);
cx.render(rsx! {
div {

View file

@ -20,8 +20,8 @@ fn main() {
const _STYLE: &str = manganis::mg!(file("./examples/assets/fileexplorer.css"));
fn app(cx: Scope) -> Element {
let files = use_ref(cx, Files::new);
fn app() -> Element {
let files = use_ref(Files::new);
cx.render(rsx! {
div {

View file

@ -7,9 +7,9 @@ fn main() {
dioxus_desktop::launch(App);
}
fn App(cx: Scope) -> Element {
let enable_directory_upload = use_state(cx, || false);
let files_uploaded: &UseRef<Vec<String>> = use_ref(cx, Vec::new);
fn App() -> Element {
let enable_directory_upload = use_state(|| false);
let files_uploaded: &UseRef<Vec<String>> = use_ref(Vec::new);
cx.render(rsx! {
label {

View file

@ -10,7 +10,7 @@ fn main() {
dioxus_desktop::launch_with_props(app, (), cfg);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx!(
div {
h1 { "drag a file here and check your console" }

View file

@ -15,7 +15,7 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
render! {
Router::<Route> {}
}
@ -36,7 +36,7 @@ enum Route {
}
#[component]
fn Footer(cx: Scope) -> Element {
fn Footer() -> Element {
render! {
div {
Outlet::<Route> { }
@ -58,21 +58,21 @@ fn Footer(cx: Scope) -> Element {
}
#[component]
fn Home(cx: Scope) -> Element {
fn Home() -> Element {
render!("Home")
}
#[component]
fn Games(cx: Scope) -> Element {
fn Games() -> Element {
render!("Games")
}
#[component]
fn Play(cx: Scope) -> Element {
fn Play() -> Element {
render!("Play")
}
#[component]
fn Settings(cx: Scope) -> Element {
fn Settings() -> Element {
render!("Settings")
}

View file

@ -9,7 +9,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
h1 { "Form" }

View file

@ -31,9 +31,9 @@ impl Label {
}
}
fn app(cx: Scope) -> Element {
let items = use_ref(cx, Vec::new);
let selected = use_state(cx, || None);
fn app() -> Element {
let items = use_ref(Vec::new);
let selected = use_state(|| None);
cx.render(rsx! {
div { class: "container",
@ -97,7 +97,7 @@ struct ActionButtonProps<'a> {
onclick: EventHandler<'a>,
}
fn ActionButton<'a>(cx: Scope<'a, ActionButtonProps<'a>>) -> Element {
fn ActionButton(props: ActionButtonProps) -> Element {
cx.render(rsx! {
div {
class: "col-sm-6 smallpad",

View file

@ -6,7 +6,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
render! {
generic_child { data: 0 }
}

View file

@ -13,7 +13,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
// This is discouraged
std::thread::sleep(std::time::Duration::from_millis(2_000));

View file

@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
render! {
div { "Hello, world!" }
}

View file

@ -20,8 +20,8 @@ fn main() {
dioxus_desktop::launch_cfg(app, Config::new().with_prerendered(content));
}
fn app(cx: Scope) -> Element {
let val = use_state(cx, || 0);
fn app() -> Element {
let val = use_state(|| 0);
cx.render(rsx! {
div {

View file

@ -5,22 +5,22 @@
use dioxus::prelude::*;
#[component]
fn Thing1<T>(cx: Scope, _a: T) -> Element {
fn Thing1<T>(_a: T) -> Element {
cx.render(rsx! { "" })
}
#[component]
fn Thing2(cx: Scope, _a: u32) -> Element<'a> {
fn Thing2(_a: u32) -> Element {
cx.render(rsx! { "" })
}
#[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! { "" })
}
#[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! { "" })
}
@ -29,8 +29,8 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
let state = use_state(cx, || 1);
fn App() -> Element {
let state = use_state(|| 1);
cx.render(rsx! {
div {

View file

@ -34,7 +34,7 @@ const FIELDS: &[(&str, &str)] = &[
("week", ""), // degrades to text most of the time
];
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div { margin_left: "30px",
{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! {
div {
select {

View file

@ -6,7 +6,7 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
cx.render(rsx! (
div {
p {
@ -38,7 +38,7 @@ enum Route {
}
#[component]
fn Header(cx: Scope) -> Element {
fn Header() -> Element {
render! {
h1 { "Your app here" }
ul {
@ -50,11 +50,11 @@ fn Header(cx: Scope) -> Element {
}
#[component]
fn Home(cx: Scope) -> Element {
fn Home() -> Element {
render!(h1 { "Home" })
}
#[component]
fn Settings(cx: Scope) -> Element {
fn Settings() -> Element {
render!(h1 { "Settings" })
}

View file

@ -7,7 +7,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
let onsubmit = move |evt: FormEvent| async move {
let resp = reqwest::Client::new()
.post("http://localhost:8080/login")

View file

@ -59,7 +59,7 @@ pub fn main() -> Result<()> {
Ok(())
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
let items = cx.use_hook(|| vec![1, 2, 3]);
log::debug!("Hello from the app");

View file

@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
button {
@ -18,7 +18,7 @@ fn app(cx: Scope) -> Element {
})
}
fn popup(cx: Scope) -> Element {
fn popup() -> Element {
cx.render(rsx! {
div { "This is a popup!" }
})

View file

@ -10,7 +10,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
onclick: move |_| println!("clicked! top"),

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_URL: &str = env!("DIOXUS_FRONT_URL");
fn App(cx: Scope) -> Element {
fn App() -> Element {
use_init_atom_root(cx);
// Retrieve the value stored in the browser's storage
let stored_auth_token = LocalStorage::get(DIOXUS_FRONT_AUTH_TOKEN)
.ok()
.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() {
*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)
.ok()
.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() {
*fermi_auth_request.write() = Some(stored_auth_request);
}

View file

@ -15,9 +15,9 @@ use openidconnect::{url::Url, OAuth2TokenResponse, TokenResponse};
#[component]
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 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 {
Some(fermi_auth_token_read) => match fermi_auth_token_read.id_token.clone() {
Some(id_token) => match log_out_url_state.get() {
@ -76,8 +76,8 @@ pub fn LogOut(cx: Scope<ClientProps>) -> Element {
#[component]
pub fn RefreshToken(cx: Scope<ClientProps>) -> Element {
let fermi_auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN);
let fermi_auth_request = use_atom_ref(cx, &FERMI_AUTH_REQUEST);
let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
let fermi_auth_token_read = fermi_auth_token.read().clone();
cx.render(match fermi_auth_token_read {
Some(fermi_auth_client_read) => match fermi_auth_client_read.refresh_token {
@ -128,9 +128,9 @@ pub fn RefreshToken(cx: Scope<ClientProps>) -> Element {
}
#[component]
pub fn LoadClient(cx: Scope) -> Element {
let init_client_future = use_future(cx, (), |_| async move { init_oidc_client().await });
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(cx, &FERMI_CLIENT);
pub fn LoadClient() -> Element {
let init_client_future = use_future((), |_| async move { init_oidc_client().await });
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(&FERMI_CLIENT);
cx.render(match init_client_future.value() {
Some(client_props) => match client_props {
Ok((client_id, client)) => {
@ -162,10 +162,10 @@ pub fn LoadClient(cx: Scope) -> Element {
}
#[component]
pub fn AuthHeader(cx: Scope) -> Element {
let auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN);
let fermi_auth_request = use_atom_ref(cx, &FERMI_AUTH_REQUEST);
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(cx, &FERMI_CLIENT);
pub fn AuthHeader() -> Element {
let auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
let fermi_auth_request = use_atom_ref(&FERMI_AUTH_REQUEST);
let fermi_client: &UseAtomRef<ClientState> = use_atom_ref(&FERMI_CLIENT);
let client = fermi_client.read().oidc_client.clone();
let auth_request_read = fermi_auth_request.read().clone();
let auth_token_read = auth_token.read().clone();

View file

@ -1,5 +1,5 @@
use dioxus::prelude::*;
pub fn Home(cx: Scope) -> Element {
pub fn Home() -> Element {
render! { div { "Hello world" } }
}

View file

@ -10,11 +10,11 @@ use fermi::*;
use openidconnect::{OAuth2TokenResponse, TokenResponse};
#[component]
pub fn Login(cx: Scope, query_string: String) -> Element {
let fermi_client = use_atom_ref(cx, &FERMI_CLIENT);
let fermi_auth_token = use_atom_ref(cx, &FERMI_AUTH_TOKEN);
pub fn Login(query_string: String) -> Element {
let fermi_client = use_atom_ref(&FERMI_CLIENT);
let fermi_auth_token = use_atom_ref(&FERMI_AUTH_TOKEN);
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 auth_token_read = fermi_auth_token.read().clone();
cx.render(match (client, auth_token_read) {

View file

@ -1,7 +1,7 @@
use dioxus::prelude::*;
#[component]
pub fn NotFound(cx: Scope, route: Vec<String>) -> Element {
pub fn NotFound(route: Vec<String>) -> Element {
render! {
div{
{route.join("")}

View file

@ -10,7 +10,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
Button {
a: "asd".to_string(),

View file

@ -5,7 +5,7 @@ fn main() {
dioxus_desktop::launch_cfg(app, make_config());
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
width: "100%",

View file

@ -37,8 +37,8 @@ fn main() {
const STYLE: &str = include_str!("./assets/calculator.css");
fn app(cx: Scope) -> Element {
let state = use_ref(cx, Calculator::new);
fn app() -> Element {
let state = use_ref(Calculator::new);
cx.render(rsx! {
style { {STYLE} }
@ -121,13 +121,13 @@ fn app(cx: Scope) -> Element {
}
#[derive(Props)]
struct CalculatorKeyProps<'a> {
name: &'a str,
onclick: EventHandler<'a, MouseEvent>,
children: Element<'a>,
struct CalculatorKeyProps {
name: String,
onclick: EventHandler<MouseEvent>,
children: Element,
}
fn CalculatorKey<'a>(cx: Scope<'a, CalculatorKeyProps<'a>>) -> Element {
fn CalculatorKey(props: CalculatorKeyProps) -> Element {
cx.render(rsx! {
button {
class: "calculator-key {cx.props.name}",

View file

@ -14,8 +14,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let state = use_state(cx, PlayerState::new);
fn app() -> Element {
let state = use_state(PlayerState::new);
cx.render(rsx!(
div {

View file

@ -63,7 +63,7 @@ impl FromQuery for ManualBlogQuerySegments {
}
#[component]
fn BlogPost(cx: Scope, query_params: ManualBlogQuerySegments) -> Element {
fn BlogPost(query_params: ManualBlogQuerySegments) -> Element {
render! {
div{"This is your blogpost with a query segment:"}
div{ "{query_params:?}" }
@ -71,7 +71,7 @@ fn BlogPost(cx: Scope, query_params: ManualBlogQuerySegments) -> Element {
}
#[component]
fn AutomaticBlogPost(cx: Scope, name: String, surname: String) -> Element {
fn AutomaticBlogPost(name: String, surname: String) -> Element {
render! {
div{"This is your blogpost with a query segment:"}
div{ "name={name}&surname={surname}" }
@ -79,7 +79,7 @@ fn AutomaticBlogPost(cx: Scope, name: String, surname: String) -> Element {
}
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
render! { Router::<Route>{} }
}

View file

@ -25,10 +25,10 @@ fn main() {
);
}
fn app(cx: Scope) -> Element {
let div_element: &UseRef<Option<Rc<MountedData>>> = use_ref(cx, || None);
fn app() -> Element {
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!(
div {

View file

@ -8,8 +8,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let mut count = use_state(cx, || 0);
fn app() -> Element {
let mut count = use_state(|| 0);
cx.render(rsx! {
h1 { "High-Five counter: {count}" }

View file

@ -36,14 +36,14 @@ enum Route {
// ANCHOR_END: router
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
render! {
Router::<Route> {}
}
}
#[component]
fn NavBar(cx: Scope) -> Element {
fn NavBar() -> Element {
render! {
nav {
ul {
@ -56,14 +56,14 @@ fn NavBar(cx: Scope) -> Element {
}
#[component]
fn Home(cx: Scope) -> Element {
fn Home() -> Element {
render! {
h1 { "Welcome to the Dioxus Blog!" }
}
}
#[component]
fn Blog(cx: Scope) -> Element {
fn Blog() -> Element {
render! {
h1 { "Blog" }
Outlet::<Route> {}
@ -71,7 +71,7 @@ fn Blog(cx: Scope) -> Element {
}
#[component]
fn BlogList(cx: Scope) -> Element {
fn BlogList() -> Element {
render! {
h2 { "Choose a post" }
ul {
@ -92,14 +92,14 @@ fn BlogList(cx: Scope) -> Element {
}
#[component]
fn BlogPost(cx: Scope, name: String) -> Element {
fn BlogPost(name: String) -> Element {
render! {
h2 { "Blog Post: {name}"}
}
}
#[component]
fn PageNotFound(cx: Scope, route: Vec<String>) -> Element {
fn PageNotFound(route: Vec<String>) -> Element {
render! {
h1 { "Page not found" }
p { "We are terribly sorry, but the page you requested doesn't exist." }

View file

@ -12,15 +12,15 @@ fn main() {
renderer.render(&vdom);
}
fn example(cx: Scope) -> Element {
let items = use_state(cx, || {
fn example() -> Element {
let items = use_state(|| {
vec![Thing {
a: "asd".to_string(),
b: 10,
}]
});
let things = use_ref(cx, || {
let things = use_ref(|| {
vec![Thing {
a: "asd".to_string(),
b: 10,
@ -28,7 +28,7 @@ fn example(cx: Scope) -> Element {
});
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();
cx.render(rsx!(

View file

@ -49,7 +49,7 @@ use baller::Baller;
use dioxus::prelude::*;
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
let formatting = "formatting!";
let formatting_tuple = ("a", "b");
let lazy_fmt = format_args!("lazily formatted text");
@ -205,7 +205,7 @@ fn App(cx: Scope) -> Element {
// helper functions
// Anything that implements IntoVnode can be dropped directly into Rsx
{helper(cx, "hello world!")}
{helper("hello world!")}
// Strings can be supplied directly
{String::from("Hello world!")}
@ -223,7 +223,7 @@ fn format_dollars(dollars: u32, cents: u32) -> String {
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! {
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,
// something like Clippy.
#[component(no_case_check)]
fn lowercase_helper(cx: Scope) -> Element {
fn lowercase_helper() -> Element {
cx.render(rsx! {
"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,
// something like Clippy.
#[component(no_case_check)]
pub fn lowercase_component(cx: Scope) -> Element {
pub fn lowercase_component() -> Element {
cx.render(rsx! { "look ma, no uppercase" })
}
}
@ -263,12 +263,12 @@ mod baller {
pub struct TallerProps<'a> {
/// Fields are documented and accessible in rsx!
a: &'static str,
children: Element<'a>,
children: Element,
}
/// Documention for this component is visible within the rsx macro
#[component]
pub fn Taller<'a>(cx: Scope<'a, TallerProps<'a>>) -> Element {
pub fn Taller(props: TallerProps -> Element {
cx.render(rsx! {
{&cx.props.children}
})
@ -297,7 +297,7 @@ fn WithInline<'a>(cx: Scope<'a>, text: &'a str) -> Element {
}
#[component]
fn Label<T>(cx: Scope, text: T) -> Element
fn Label<T>(text: T) -> Element
where
T: Display,
{

View file

@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let header_element = use_ref(cx, || None);
fn app() -> Element {
let header_element = use_ref(|| None);
cx.render(rsx!(
div {

View file

@ -27,8 +27,8 @@ impl CoolData {
#[component]
#[rustfmt::skip]
pub fn App(cx: Scope) -> Element {
use_shared_state_provider(cx, || CoolData::new(HashMap::from([
pub fn App() -> Element {
use_shared_state_provider(|| CoolData::new(HashMap::from([
(0, "Hello, World!".to_string()),
(1, "Dioxus is amazing!".to_string())
])));
@ -50,8 +50,8 @@ pub fn App(cx: Scope) -> Element {
}
#[component]
fn DataEditor(cx: Scope, id: usize) -> Element {
let data = use_shared_state::<CoolData>(cx)?;
fn DataEditor(id: usize) -> Element {
let data = use_shared_state::<CoolData>()?;
render! {
p {
@ -61,8 +61,8 @@ fn DataEditor(cx: Scope, id: usize) -> Element {
}
#[component]
fn DataView(cx: Scope, id: usize) -> Element {
let data = use_shared_state::<CoolData>(cx)?;
fn DataView(id: usize) -> Element {
let data = use_shared_state::<CoolData>()?;
render! {
input {

View file

@ -5,10 +5,10 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let toggled = use_state(cx, || false);
fn app() -> Element {
let toggled = use_state(|| false);
use_global_shortcut(cx, "ctrl+s", {
use_global_shortcut("ctrl+s", {
to_owned![toggled];
move || toggled.modify(|t| !*t)
});

View file

@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
let a = 123;
let b = 456;
let c = 789;
@ -30,7 +30,7 @@ fn Component<'a>(
a: i32,
b: i32,
c: i32,
children: Element<'a>,
children: Element,
onclick: EventHandler<'a, ()>,
) -> Element {
render! {

View file

@ -5,14 +5,14 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let running = dioxus_signals::use_signal(cx, || true);
let mut count = dioxus_signals::use_signal(cx, || 0);
let saved_values = dioxus_signals::use_signal(cx, || vec![0.to_string()]);
fn app() -> Element {
let running = dioxus_signals::use_signal(|| true);
let mut count = dioxus_signals::use_signal(|| 0);
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 are backed by a runtime that is designed to deeply integrate with Dioxus apps
use_future!(cx, || async move {
use_future!(|| async move {
loop {
if running.value() {
count += 1;

View file

@ -13,7 +13,7 @@ fn main() {
}
#[component]
fn App(cx: Scope) -> Element {
fn App() -> Element {
render! {
Router::<Route> {}
}
@ -38,7 +38,7 @@ enum Route {
}
#[component]
fn NavBar(cx: Scope) -> Element {
fn NavBar() -> Element {
render! {
h1 { "Your app here" }
ul {
@ -53,19 +53,19 @@ fn NavBar(cx: Scope) -> Element {
}
#[component]
fn Home(cx: Scope) -> Element {
fn Home() -> Element {
log::debug!("rendering home {:?}", cx.scope_id());
render! { h1 { "Home" } }
}
#[component]
fn BlogList(cx: Scope) -> Element {
fn BlogList() -> Element {
log::debug!("rendering blog list {:?}", cx.scope_id());
render! { div { "Blog List" } }
}
#[component]
fn BlogPost(cx: Scope, post: String) -> Element {
fn BlogPost(post: String) -> Element {
log::debug!("rendering blog post {}", post);
render! {
@ -77,6 +77,6 @@ fn BlogPost(cx: Scope, post: String) -> Element {
}
#[component]
fn Oranges(cx: Scope) -> Element {
fn Oranges() -> Element {
render!("Oranges are not apples!")
}

View file

@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx!(
div {
// Use Map directly to lazily pull elements

View file

@ -13,12 +13,12 @@ enum Route {
}
#[component]
fn Homepage(cx: Scope) -> Element {
fn Homepage() -> Element {
render! { h1 { "Welcome home" } }
}
#[component]
fn Blog(cx: Scope, id: String) -> Element {
fn Blog(id: String) -> Element {
render! {
h1 { "How to make: " }
p { "{id}" }
@ -26,7 +26,7 @@ fn Blog(cx: Scope, id: String) -> Element {
}
#[component]
fn Nav(cx: Scope) -> Element {
fn Nav() -> Element {
render! {
nav {
li { Link { to: Route::Homepage { }, "Go home" } }

View file

@ -8,7 +8,7 @@ fn main() {
println!("{}", html);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
render! {
Component {
width: "10px",
@ -21,7 +21,7 @@ fn app(cx: Scope) -> Element {
}
#[component]
fn Component<'a>(cx: Scope<'a, Props<'a>>) -> Element<'a> {
fn Component(props: Props -> Element {
render! {
audio { ..cx.props.attributes, "1: {cx.props.extra_data}\n2: {cx.props.extra_data2}" }
}

View file

@ -30,7 +30,7 @@ fn main() {
println!("{file}");
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx!(
div {
h1 { "Title" }

View file

@ -7,10 +7,10 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let count = use_signal(cx, || 10);
fn app() -> Element {
let count = use_signal(|| 10);
use_future(cx, (), |_| async move {
use_future((), |_| async move {
let mut stream = some_stream();
while let Some(second) = stream.next().await {

View file

@ -31,7 +31,7 @@ struct DogApi {
message: String,
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {
h1 {"Dogs are very important"}
@ -52,8 +52,8 @@ fn app(cx: Scope) -> Element {
/// This component will re-render when the future has finished
/// Suspense is achieved my moving the future into only the component that
/// actually renders the data.
fn Doggo(cx: Scope) -> Element {
let fut = use_future(cx, (), |_| async move {
fn Doggo() -> Element {
let fut = use_future((), |_| async move {
reqwest::get("https://dog.ceo/api/breeds/image/random/")
.await
.unwrap()

View file

@ -6,8 +6,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let val = use_state(cx, || 5);
fn app() -> Element {
let val = use_state(|| 5);
cx.render(rsx! {
div {
@ -58,7 +58,7 @@ const UNHELD_COLOR: &str = "#ddd";
// A six-sided die (D6) with dots.
#[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 active_dots = &DOTS_FOR_VALUE[(value - 1) as usize];

View file

@ -1,6 +1,6 @@
use dioxus::prelude::*;
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx!( svg {
width: "200",
height: "250",

View file

@ -11,7 +11,7 @@ fn main() {
dioxus_web::launch(app);
}
pub fn app(cx: Scope) -> Element {
pub fn app() -> Element {
let grey_background = true;
cx.render(rsx!(
div {
@ -78,7 +78,7 @@ pub fn app(cx: Scope) -> Element {
))
}
pub fn StacksIcon(cx: Scope) -> Element {
pub fn StacksIcon() -> Element {
cx.render(rsx!(
svg {
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!(
svg {
fill: "none",

View file

@ -9,10 +9,10 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let count = use_state(cx, || 0);
fn app() -> Element {
let count = use_state(|| 0);
use_future(cx, (), move |_| {
use_future((), move |_| {
let mut count = count.clone();
async move {
loop {

View file

@ -6,8 +6,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let model = use_state(cx, || String::from("asd"));
fn app() -> Element {
let model = use_state(|| String::from("asd"));
println!("{model}");

View file

@ -22,8 +22,8 @@ pub struct TodoItem {
}
pub fn app(cx: Scope<()>) -> Element {
let todos = use_state(cx, im_rc::HashMap::<u32, TodoItem>::default);
let filter = use_state(cx, || FilterState::All);
let todos = use_state(im_rc::HashMap::<u32, TodoItem>::default);
let filter = use_state(|| FilterState::All);
// Filter the todos based on the filter state
let mut filtered_todos = todos
@ -94,9 +94,9 @@ pub struct TodoHeaderProps<'a> {
todos: &'a UseState<im_rc::HashMap<u32, TodoItem>>,
}
pub fn TodoHeader<'a>(cx: Scope<'a, TodoHeaderProps<'a>>) -> Element {
let draft = use_state(cx, || "".to_string());
let todo_id = use_state(cx, || 0);
pub fn TodoHeader(props: TodoHeaderProps -> Element {
let draft = use_state(|| "".to_string());
let todo_id = use_state(|| 0);
cx.render(rsx! {
header { class: "header",
@ -137,8 +137,8 @@ pub struct TodoEntryProps<'a> {
id: u32,
}
pub fn TodoEntry<'a>(cx: Scope<'a, TodoEntryProps<'a>>) -> Element {
let is_editing = use_state(cx, || false);
pub fn TodoEntry(props: TodoEntryProps -> Element {
let is_editing = use_state(|| false);
let todos = cx.props.todos.get();
let todo = &todos[&cx.props.id];
@ -199,7 +199,7 @@ pub struct ListFooterProps<'a> {
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_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! {
footer { class: "info",
p { "Double-click to edit a todo" }

View file

@ -29,8 +29,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
use_asset_handler(cx, "videos", move |request, responder| {
fn app() -> Element {
use_asset_handler("videos", move |request, responder| {
// Using dioxus::spawn works, but is slower than a dedicated thread
tokio::task::spawn(async move {
let video_file = PathBuf::from(VIDEO_PATH);

View file

@ -4,7 +4,7 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
web-component {
"my-prop": "5%",

View file

@ -11,16 +11,16 @@ fn main() {
dioxus_desktop::launch_cfg(app, cfg);
}
fn app(cx: Scope) -> Element {
fn app() -> Element {
let window = dioxus_desktop::use_window(cx);
// if you want to make window fullscreen, you need close the resizable.
// window.set_fullscreen(true);
// window.set_resizable(false);
let fullscreen = use_state(cx, || false);
let always_on_top = use_state(cx, || false);
let decorations = use_state(cx, || false);
let fullscreen = use_state(|| false);
let always_on_top = use_state(|| false);
let decorations = use_state(|| false);
cx.render(rsx!(
link { href:"https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css", rel:"stylesheet" }

View file

@ -10,10 +10,10 @@ fn main() {
dioxus_desktop::launch_cfg(app, cfg);
}
fn app(cx: Scope) -> Element {
let focused = use_state(cx, || false);
fn app() -> Element {
let focused = use_state(|| false);
use_wry_event_handler(cx, {
use_wry_event_handler({
to_owned![focused];
move |event, _| {
if let WryEvent::WindowEvent {

View file

@ -4,8 +4,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let level = use_state(cx, || 1.0);
fn app() -> Element {
let level = use_state(|| 1.0);
cx.render(rsx! {
input {

View file

@ -8,10 +8,8 @@ fn main() {
dioxus_desktop::launch(app);
}
fn app(cx: Scope) -> Element {
let contents = use_state(cx, || {
String::from("<script>alert(\"hello world\")</script>")
});
fn app() -> Element {
let contents = use_state(|| String::from("<script>alert(\"hello world\")</script>"));
cx.render(rsx! {
div {

View file

@ -55,8 +55,8 @@
Dioxus 是一个可移植的、高性能的、符合人体工程学的框架,使用 Rust 语言构建跨平台的用户界面。
```rust
fn app(cx: Scope) -> Element {
let mut count = use_state(cx, || 0);
fn app() -> Element {
let mut count = use_state(|| 0);
cx.render(rsx! {
h1 { "High-Five counter: {count}" }

View file

@ -5,8 +5,8 @@ pub fn Explainer<'a>(
cx: Scope<'a>,
invert: bool,
title: &'static str,
content: Element<'a>,
flasher: Element<'a>,
content: Element,
flasher: Element,
) -> Element {
// pt-5 sm:pt-24 lg:pt-24

View file

@ -1,4 +1,4 @@
fn SaveClipboard(cx: Scope) -> Element {
fn SaveClipboard() -> Element {
rsx! {
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",

View file

@ -1,3 +1,3 @@
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! { div { "hello world" } })
}

View file

@ -1,4 +1,4 @@
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {"hello world" }
})

View file

@ -1,3 +1,3 @@
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! { div { "hello world" } })
}

View file

@ -1,4 +1,4 @@
fn app(cx: Scope) -> Element {
fn app() -> Element {
cx.render(rsx! {
div {"hello world" }
})

View file

@ -279,7 +279,7 @@ mod tests {
#[test]
fn test_no_hooks() {
let contents = indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
rsx! {
p { "Hello World" }
}
@ -294,8 +294,8 @@ mod tests {
#[test]
fn test_hook_correctly_used_inside_component() {
let contents = indoc! {r#"
fn App(cx: Scope) -> Element {
let count = use_state(cx, || 0);
fn App() -> Element {
let count = use_state(|| 0);
rsx! {
p { "Hello World: {count}" }
}
@ -310,8 +310,8 @@ mod tests {
#[test]
fn test_hook_correctly_used_inside_hook_fn() {
let contents = indoc! {r#"
fn use_thing(cx: Scope) -> UseState<i32> {
use_state(cx, || 0)
fn use_thing() -> UseState<i32> {
use_state(|| 0)
}
"#};
@ -323,9 +323,9 @@ mod tests {
#[test]
fn test_hook_correctly_used_inside_hook_closure() {
let contents = indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
let use_thing = || {
use_state(cx, || 0)
use_state(|| 0)
};
let count = use_thing();
rsx! {
@ -342,9 +342,9 @@ mod tests {
#[test]
fn test_conditional_hook_if() {
let contents = indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
if you_are_happy && you_know_it {
let something = use_state(cx, || "hands");
let something = use_state(|| "hands");
println!("clap your {something}")
}
}
@ -357,7 +357,7 @@ mod tests {
vec![Issue::HookInsideConditional(
HookInfo::new(
Span::new_from_str(
r#"use_state(cx, || "hands")"#,
r#"use_state(|| "hands")"#,
LineColumn { line: 3, column: 24 },
),
Span::new_from_str(
@ -368,7 +368,7 @@ mod tests {
),
ConditionalInfo::If(IfInfo::new(
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 },
),
Span::new_from_str(
@ -383,10 +383,10 @@ mod tests {
#[test]
fn test_conditional_hook_match() {
let contents = indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
match you_are_happy && you_know_it {
true => {
let something = use_state(cx, || "hands");
let something = use_state(|| "hands");
println!("clap your {something}")
}
false => {}
@ -400,13 +400,13 @@ mod tests {
report.issues,
vec![Issue::HookInsideConditional(
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 }),
"use_state".to_string()
),
ConditionalInfo::Match(MatchInfo::new(
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 },
),
Span::new_from_str("match you_are_happy && you_know_it", LineColumn { line: 2, column: 4 })
@ -418,9 +418,9 @@ mod tests {
#[test]
fn test_for_loop_hook() {
let contents = indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
for _name in &names {
let is_selected = use_state(cx, || false);
let is_selected = use_state(|| false);
println!("selected: {is_selected}");
}
}
@ -433,7 +433,7 @@ mod tests {
vec![Issue::HookInsideLoop(
HookInfo::new(
Span::new_from_str(
"use_state(cx, || false)",
"use_state(|| false)",
LineColumn { line: 3, column: 26 },
),
Span::new_from_str(
@ -444,7 +444,7 @@ mod tests {
),
AnyLoopInfo::For(ForInfo::new(
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 },
),
Span::new_from_str(
@ -459,9 +459,9 @@ mod tests {
#[test]
fn test_while_loop_hook() {
let contents = indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
while true {
let something = use_state(cx, || "hands");
let something = use_state(|| "hands");
println!("clap your {something}")
}
}
@ -474,7 +474,7 @@ mod tests {
vec![Issue::HookInsideLoop(
HookInfo::new(
Span::new_from_str(
r#"use_state(cx, || "hands")"#,
r#"use_state(|| "hands")"#,
LineColumn { line: 3, column: 24 },
),
Span::new_from_str(
@ -485,7 +485,7 @@ mod tests {
),
AnyLoopInfo::While(WhileInfo::new(
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 },
),
Span::new_from_str(
@ -500,9 +500,9 @@ mod tests {
#[test]
fn test_loop_hook() {
let contents = indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
loop {
let something = use_state(cx, || "hands");
let something = use_state(|| "hands");
println!("clap your {something}")
}
}
@ -515,7 +515,7 @@ mod tests {
vec![Issue::HookInsideLoop(
HookInfo::new(
Span::new_from_str(
r#"use_state(cx, || "hands")"#,
r#"use_state(|| "hands")"#,
LineColumn { line: 3, column: 24 },
),
Span::new_from_str(
@ -525,7 +525,7 @@ mod tests {
"use_state".to_string()
),
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 },
)))
)],
@ -535,8 +535,8 @@ mod tests {
#[test]
fn test_conditional_okay() {
let contents = indoc! {r#"
fn App(cx: Scope) -> Element {
let something = use_state(cx, || "hands");
fn App() -> Element {
let something = use_state(|| "hands");
if you_are_happy && you_know_it {
println!("clap your {something}")
}
@ -551,9 +551,9 @@ mod tests {
#[test]
fn test_closure_hook() {
let contents = indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
let _a = || {
let b = use_state(cx, || 0);
let b = use_state(|| 0);
b.get()
};
}
@ -566,7 +566,7 @@ mod tests {
vec![Issue::HookInsideClosure(
HookInfo::new(
Span::new_from_str(
"use_state(cx, || 0)",
"use_state(|| 0)",
LineColumn {
line: 3,
column: 16
@ -582,7 +582,7 @@ mod tests {
"use_state".to_string()
),
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 {
line: 2,
column: 13
@ -595,8 +595,8 @@ mod tests {
#[test]
fn test_hook_outside_component() {
let contents = indoc! {r#"
fn not_component_or_hook(cx: Scope) {
let _a = use_state(cx, || 0);
fn not_component_or_hook() {
let _a = use_state(|| 0);
}
"#};
@ -606,7 +606,7 @@ mod tests {
report.issues,
vec![Issue::HookOutsideComponent(HookInfo::new(
Span::new_from_str(
"use_state(cx, || 0)",
"use_state(|| 0)",
LineColumn {
line: 2,
column: 13
@ -627,8 +627,8 @@ mod tests {
#[test]
fn test_hook_inside_hook() {
let contents = indoc! {r#"
fn use_thing(cx: Scope) {
let _a = use_state(cx, || 0);
fn use_thing() {
let _a = use_state(|| 0);
}
"#};

View file

@ -230,9 +230,9 @@ mod tests {
let issue_report = check_file(
"src/main.rs".into(),
indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
if you_are_happy && you_know_it {
let something = use_state(cx, || "hands");
let something = use_state(|| "hands");
println!("clap your {something}")
}
}
@ -243,7 +243,7 @@ mod tests {
error: hook called conditionally: `use_state` (inside `if`)
--> 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
@ -258,10 +258,10 @@ mod tests {
let issue_report = check_file(
"src/main.rs".into(),
indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
match you_are_happy && you_know_it {
true => {
let something = use_state(cx, || "hands");
let something = use_state(|| "hands");
println!("clap your {something}")
}
_ => {}
@ -274,7 +274,7 @@ mod tests {
error: hook called conditionally: `use_state` (inside `match`)
--> 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
@ -289,9 +289,9 @@ mod tests {
let issue_report = check_file(
"src/main.rs".into(),
indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
for i in 0..10 {
let something = use_state(cx, || "hands");
let something = use_state(|| "hands");
println!("clap your {something}")
}
}
@ -302,7 +302,7 @@ mod tests {
error: hook called in a loop: `use_state` (inside `for` loop)
--> 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
@ -317,9 +317,9 @@ mod tests {
let issue_report = check_file(
"src/main.rs".into(),
indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
while check_thing() {
let something = use_state(cx, || "hands");
let something = use_state(|| "hands");
println!("clap your {something}")
}
}
@ -330,7 +330,7 @@ mod tests {
error: hook called in a loop: `use_state` (inside `while` loop)
--> 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
@ -345,9 +345,9 @@ mod tests {
let issue_report = check_file(
"src/main.rs".into(),
indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
loop {
let something = use_state(cx, || "hands");
let something = use_state(|| "hands");
println!("clap your {something}")
}
}
@ -358,7 +358,7 @@ mod tests {
error: hook called in a loop: `use_state` (inside `loop`)
--> src/main.rs:3:25
|
3 | let something = use_state(cx, || "hands");
3 | let something = use_state(|| "hands");
| ^^^^^^^^^
|
= note: `loop { }` is the loop
@ -373,9 +373,9 @@ mod tests {
let issue_report = check_file(
"src/main.rs".into(),
indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
let something = || {
let something = use_state(cx, || "hands");
let something = use_state(|| "hands");
println!("clap your {something}")
};
}
@ -386,7 +386,7 @@ mod tests {
error: hook called in a closure: `use_state`
--> 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(
"src/main.rs".into(),
indoc! {r#"
fn App(cx: Scope) -> Element {
fn App() -> Element {
if you_are_happy && you_know_it {
let something = use_state(cx, || {
let something = use_state(|| {
"hands"
});
println!("clap your {something}")
@ -414,7 +414,7 @@ mod tests {
error: hook called conditionally: `use_state` (inside `if`)
--> src/main.rs:3:25
|
3 | let something = use_state(cx, || {
3 | let something = use_state(|| {
| ^^^^^^^^^
4 | "hands"
5 | });

View file

@ -3,7 +3,7 @@
pub struct HookInfo {
/// The name of the hook, e.g. `use_state`.
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,
/// The span of the name, e.g. `use_state`.
pub name_span: Span,

View file

@ -71,7 +71,7 @@ fn write_callbody_with_icon_section(mut callbody: CallBody) -> 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);
out.push_str(" })\n}");
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();
out.push_str("\n\n pub fn icon_");
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);
out.push_str(" })\n }");
}

View file

@ -36,7 +36,7 @@ async fn setup_file_watcher<F: Fn() -> Result<BuildResult> + Send + 'static>(
if let Some(hot_reload) = &hot_reload {
// find changes to the rsx in the file
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
needs_full_rebuild = false;
@ -143,6 +143,6 @@ pub(crate) trait Platform {
#[derive(Clone)]
pub struct HotReloadState {
pub messages: broadcast::Sender<Template<'static>>,
pub messages: broadcast::Sender<Template>,
pub file_map: Arc<Mutex<FileMap<HtmlCtx>>>,
}

View file

@ -66,11 +66,11 @@
//! use dioxus::prelude::*;
//!
//! #[name_changer(CoolName)]
//! pub fn LameName(cx: Scope) -> Element {
//! pub fn LameName() -> Element {
//! render! { "I want a cool name!" }
//! }
//!
//! pub fn App(cx: Scope) -> Element {
//! pub fn App() -> Element {
//! render! { CoolName {} } // Renders: "I want a cool name!"
//! }
//! ```

View file

@ -65,7 +65,7 @@ pub fn render(s: TokenStream) -> TokenStream {
/// # Example
/// ```rust,ignore
/// #[inline_props]
/// fn app(cx: Scope, bob: String) -> Element {
/// fn app(bob: String) -> Element {
/// cx.render(rsx!("hello, {bob}"))
/// }
///
@ -128,17 +128,17 @@ pub(crate) const COMPONENT_ARG_CASE_CHECK_OFF: &str = "no_case_check";
/// * Without props:
/// ```rust,ignore
/// #[component]
/// fn GreetBob(cx: Scope) -> Element {
/// fn GreetBob() -> Element {
/// render! { "hello, bob" }
/// }
///
/// // is equivalent to
///
/// #[allow(non_snake_case)]
/// fn GreetBob(cx: Scope) -> Element {
/// fn GreetBob() -> Element {
/// #[warn(non_snake_case)]
/// #[inline(always)]
/// fn __dx_inner_comp(cx: Scope) -> Element {
/// fn __dx_inner_comp() -> Element {
/// render! { "hello, bob" }
/// }
/// // 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:
/// ```rust,ignore
/// #[component(no_case_check)]
/// fn GreetPerson(cx: Scope, person: String) -> Element {
/// fn GreetPerson(person: String) -> Element {
/// render! { "hello, {person}" }
/// }
///
@ -162,10 +162,10 @@ pub(crate) const COMPONENT_ARG_CASE_CHECK_OFF: &str = "no_case_check";
/// }
///
/// #[allow(non_snake_case)]
/// fn GreetPerson<'a>(cx: Scope<'a, GreetPersonProps>) -> Element {
/// fn GreetPerson(props: GreetPersonProps>) -> Element {
/// #[warn(non_snake_case)]
/// #[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;
/// {
/// render! { "hello, {person}" }

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")
}
pub fn use_hook<State: Clone + 'static>(initializer: impl FnOnce() -> State) -> State {
once(initializer)
}
/// Get the current render since the inception of this component
///
/// This can be used as a helpful diagnostic when debugging hooks/renders, etc

View file

@ -87,7 +87,7 @@ pub mod prelude {
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,
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,
ScopeId, Task, Template, TemplateAttribute, TemplateNode, Throw, VNode, VNodeInner,
VirtualDom,

View file

@ -1,6 +1,9 @@
use crate::any_props::{BoxedAnyProps, VProps};
use crate::innerlude::{ElementRef, EventHandler, MountId, ScopeState};
use crate::innerlude::{ElementRef, EventHandler, MountId};
use crate::properties::ComponentFunction;
use crate::{
any_props::{BoxedAnyProps, VProps},
innerlude::ScopeState,
};
use crate::{arena::ElementId, Element, Event};
use crate::{Properties, VirtualDom};
use std::ops::Deref;
@ -16,7 +19,7 @@ pub type TemplateId = &'static str;
/// 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.
///
/// 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
/// // Without explicit props
/// fn(Scope) -> Element;
/// fn() -> Element;
/// async fn(Scope<'_>) -> Element;
///
/// // With explicit props

View file

@ -1,9 +1,9 @@
use crate::{
any_props::{AnyProps, BoxedAnyProps},
innerlude::DirtyScope,
innerlude::{DirtyScope, ScopeState},
nodes::RenderReturn,
scope_context::ScopeContext,
scopes::{ScopeId, ScopeState},
scopes::ScopeId,
virtual_dom::VirtualDom,
};

View file

@ -254,7 +254,7 @@ impl ScopeContext {
/// use dioxus_core::ScopeState;
///
/// // 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!"));
/// }
/// ```

View file

@ -6,13 +6,13 @@ use crate::{
any_props::{BoxedAnyProps, VProps},
arena::ElementId,
innerlude::{
DirtyScope, ElementRef, ErrorBoundary, NoOpMutations, Scheduler, SchedulerMsg, VNodeMount,
WriteMutations,
DirtyScope, ElementRef, ErrorBoundary, NoOpMutations, Scheduler, SchedulerMsg, ScopeState,
VNodeMount, WriteMutations,
},
nodes::RenderReturn,
nodes::{Template, TemplateId},
runtime::{Runtime, RuntimeGuard},
scopes::{ScopeId, ScopeState},
scopes::ScopeId,
AttributeValue, Element, Event, MutationsVec,
};
use futures_util::{pin_mut, StreamExt};

View file

@ -1,8 +1,8 @@
use dioxus::prelude::*;
fn app(cx: Scope) -> Element {
let state = use_state(cx, || 0);
use_future(cx, (), |_| {
fn app() -> Element {
let state = use_state(|| 0);
use_future((), |_| {
to_owned![state];
async move {
loop {

Some files were not shown because too many files have changed in this diff Show more