From 7d872904edfff68daf444ce02902f42a189784f0 Mon Sep 17 00:00:00 2001 From: Leonard Date: Thu, 14 Sep 2023 14:16:31 +0200 Subject: [PATCH] Add `#[component]` to components that don't have it --- docs-src/0.4/en/reference/use_coroutine.md | 4 +++- examples/prerender.rs | 2 +- src/components/homepage/hero.rs | 2 ++ src/doc_examples/event_nested.rs | 2 +- src/doc_examples/event_prevent_default.rs | 2 +- src/doc_examples/hackernews_state.rs | 1 - src/doc_examples/hello_world.rs | 3 +-- src/doc_examples/hello_world_ssr.rs | 2 -- src/doc_examples/hooks_counter_two_state.rs | 2 +- src/doc_examples/hydration.rs | 9 +++++---- src/doc_examples/input_controlled.rs | 2 +- src/doc_examples/input_fileengine_async.rs | 2 +- src/doc_examples/readme_expanded.rs | 5 +++-- src/doc_examples/server_data_fetch.rs | 7 ++++--- src/doc_examples/server_data_prefetch.rs | 7 ++++--- src/doc_examples/spawn.rs | 5 ++++- src/doc_examples/use_coroutine.rs | 3 ++- 17 files changed, 34 insertions(+), 26 deletions(-) diff --git a/docs-src/0.4/en/reference/use_coroutine.md b/docs-src/0.4/en/reference/use_coroutine.md index 017d4a08a..c847af3d1 100644 --- a/docs-src/0.4/en/reference/use_coroutine.md +++ b/docs-src/0.4/en/reference/use_coroutine.md @@ -145,7 +145,8 @@ We can combine coroutines with [Fermi](https://docs.rs/fermi/latest/fermi/index. ```rust, no_run static USERNAME: Atom = Atom(|_| "default".to_string()); -fn app(cx: Scope) -> Element { +#[component] +fn App(cx: Scope) -> Element { let atoms = use_atom_root(cx); use_coroutine(cx, |rx| sync_service(rx, atoms.clone())); @@ -155,6 +156,7 @@ fn app(cx: Scope) -> Element { }) } +#[component] fn Banner(cx: Scope) -> Element { let username = use_read(cx, &USERNAME); diff --git a/examples/prerender.rs b/examples/prerender.rs index 710d04560..4aeaf1cf8 100644 --- a/examples/prerender.rs +++ b/examples/prerender.rs @@ -5,7 +5,7 @@ //! cargo run --features ssr --example prerender //! ``` -#![allow(non_snake_case, unused)] +#![allow(unused)] use dioxus::prelude::*; use dioxus_docs_site::*; use dioxus_fullstack::{launch, prelude::*}; diff --git a/src/components/homepage/hero.rs b/src/components/homepage/hero.rs index ad5c5b8c1..3423f008e 100644 --- a/src/components/homepage/hero.rs +++ b/src/components/homepage/hero.rs @@ -59,6 +59,7 @@ pub fn Hero(cx: Scope) -> Element { static ADD_TO_CLIPBOARD: &str = r#"navigator.clipboard.writeText("cargo add dioxus")"#; +#[component] fn SaveClipboard(cx: Scope) -> Element { let saved = use_state(cx, || false); @@ -79,6 +80,7 @@ fn SaveClipboard(cx: Scope) -> Element { }) } +#[component] fn AnimatedIcon(cx: Scope) -> Element { let dark = include_str!("../../../public/static/multiplatform-dark.svg"); let light = include_str!("../../../public/static/multiplatform-light.svg"); diff --git a/src/doc_examples/event_nested.rs b/src/doc_examples/event_nested.rs index 4372869e3..9976777ae 100644 --- a/src/doc_examples/event_nested.rs +++ b/src/doc_examples/event_nested.rs @@ -1,10 +1,10 @@ -#![allow(non_snake_case)] use dioxus::prelude::*; fn main() { dioxus_desktop::launch(App); } +#[component] fn App(cx: Scope) -> Element { // ANCHOR: rsx cx.render(rsx! { diff --git a/src/doc_examples/event_prevent_default.rs b/src/doc_examples/event_prevent_default.rs index 0a582417a..e32ec6260 100644 --- a/src/doc_examples/event_prevent_default.rs +++ b/src/doc_examples/event_prevent_default.rs @@ -1,6 +1,6 @@ -#![allow(non_snake_case)] use dioxus::prelude::*; +#[component] pub fn App(cx: Scope) -> Element { // ANCHOR: prevent_default cx.render(rsx! { diff --git a/src/doc_examples/hackernews_state.rs b/src/doc_examples/hackernews_state.rs index b713fa587..10c3a0cc7 100644 --- a/src/doc_examples/hackernews_state.rs +++ b/src/doc_examples/hackernews_state.rs @@ -1,4 +1,3 @@ -#![allow(non_snake_case)] use dioxus::prelude::*; pub mod app_v1 { diff --git a/src/doc_examples/hello_world.rs b/src/doc_examples/hello_world.rs index 3819c8c08..dab5f6e07 100644 --- a/src/doc_examples/hello_world.rs +++ b/src/doc_examples/hello_world.rs @@ -1,7 +1,6 @@ -#![allow(non_snake_case)] - use dioxus::prelude::*; +#[component] pub fn HelloWorldCounter(cx: Scope) -> Element { cx.render(rsx! { div { diff --git a/src/doc_examples/hello_world_ssr.rs b/src/doc_examples/hello_world_ssr.rs index 0af689f49..fd49dc13c 100644 --- a/src/doc_examples/hello_world_ssr.rs +++ b/src/doc_examples/hello_world_ssr.rs @@ -1,9 +1,7 @@ #![allow(unused)] -#![allow(non_snake_case)] // ANCHOR: all // ANCHOR: main -#![allow(non_snake_case)] use axum::{response::Html, routing::get, Router}; // import the prelude to get access to the `rsx!` macro and the `Scope` and `Element` types use dioxus::prelude::*; diff --git a/src/doc_examples/hooks_counter_two_state.rs b/src/doc_examples/hooks_counter_two_state.rs index e8b0dd531..3107ebd8f 100644 --- a/src/doc_examples/hooks_counter_two_state.rs +++ b/src/doc_examples/hooks_counter_two_state.rs @@ -1,7 +1,7 @@ -#![allow(non_snake_case)] use dioxus::prelude::*; // ANCHOR: component +#[component] pub fn App(cx: Scope) -> Element { // ANCHOR: use_state_calls let mut count_a = use_state(cx, || 0); diff --git a/src/doc_examples/hydration.rs b/src/doc_examples/hydration.rs index 31574edce..5e135dcf5 100644 --- a/src/doc_examples/hydration.rs +++ b/src/doc_examples/hydration.rs @@ -1,9 +1,9 @@ -#![allow(non_snake_case, unused)] +#![allow(unused)] use dioxus::prelude::*; fn main() { #[cfg(feature = "web")] - dioxus_web::launch_cfg(app, dioxus_web::Config::new().hydrate(true)); + dioxus_web::launch_cfg(App, dioxus_web::Config::new().hydrate(true)); #[cfg(feature = "ssr")] { use dioxus_fullstack::prelude::*; @@ -14,7 +14,7 @@ fn main() { axum::Server::bind(&addr) .serve( axum::Router::new() - .serve_dioxus_application("", ServeConfigBuilder::new(app, ())) + .serve_dioxus_application("", ServeConfigBuilder::new(App, ())) .into_make_service(), ) .await @@ -23,7 +23,8 @@ fn main() { } } -fn app(cx: Scope) -> Element { +#[component] +fn App(cx: Scope) -> Element { let mut count = use_state(cx, || 0); cx.render(rsx! { diff --git a/src/doc_examples/input_controlled.rs b/src/doc_examples/input_controlled.rs index 7b55e7050..3bb917ad3 100644 --- a/src/doc_examples/input_controlled.rs +++ b/src/doc_examples/input_controlled.rs @@ -1,7 +1,7 @@ -#![allow(non_snake_case)] use dioxus::prelude::*; // ANCHOR: component +#[component] pub fn App(cx: Scope) -> Element { let name = use_state(cx, || "bob".to_string()); diff --git a/src/doc_examples/input_fileengine_async.rs b/src/doc_examples/input_fileengine_async.rs index 3da36ed65..3168f3571 100644 --- a/src/doc_examples/input_fileengine_async.rs +++ b/src/doc_examples/input_fileengine_async.rs @@ -1,7 +1,7 @@ -#![allow(non_snake_case)] use dioxus::prelude::*; // ANCHOR: component +#[component] pub fn App(cx: Scope) -> Element { let files_uploaded: &UseRef> = use_ref(cx, Vec::new); diff --git a/src/doc_examples/readme_expanded.rs b/src/doc_examples/readme_expanded.rs index f06460e47..e150d8c8a 100644 --- a/src/doc_examples/readme_expanded.rs +++ b/src/doc_examples/readme_expanded.rs @@ -1,10 +1,11 @@ use dioxus::prelude::*; fn main() { - dioxus_desktop::launch(app); + dioxus_desktop::launch(App); } -fn app(cx: Scope) -> Element { +#[component] +fn App(cx: Scope) -> Element { let mut count = use_state(cx, || 0); cx.render( diff --git a/src/doc_examples/server_data_fetch.rs b/src/doc_examples/server_data_fetch.rs index 7c4725f2f..be0cd3eef 100644 --- a/src/doc_examples/server_data_fetch.rs +++ b/src/doc_examples/server_data_fetch.rs @@ -1,13 +1,14 @@ -#![allow(non_snake_case, unused)] +#![allow(unused)] use dioxus::prelude::*; use dioxus_fullstack::prelude::*; fn main() { - LaunchBuilder::new(app).launch(); + LaunchBuilder::new(App).launch(); } -fn app(cx: Scope) -> Element { +#[component] +fn App(cx: Scope) -> Element { let mut count = use_future(cx, (), |_| async { get_server_data().await }); cx.render(rsx! { diff --git a/src/doc_examples/server_data_prefetch.rs b/src/doc_examples/server_data_prefetch.rs index 5322230c3..e1bb6ea55 100644 --- a/src/doc_examples/server_data_prefetch.rs +++ b/src/doc_examples/server_data_prefetch.rs @@ -1,13 +1,14 @@ -#![allow(non_snake_case, unused)] +#![allow(unused)] use dioxus::prelude::*; use dioxus_fullstack::prelude::*; fn main() { - LaunchBuilder::new(app).launch(); + LaunchBuilder::new(App).launch(); } -fn app(cx: Scope) -> Element { +#[component] +fn App(cx: Scope) -> Element { let mut count = use_server_future(cx, (), |_| async { get_server_data().await })?; cx.render(rsx! { diff --git a/src/doc_examples/spawn.rs b/src/doc_examples/spawn.rs index b164570d8..8f0f5cf3a 100644 --- a/src/doc_examples/spawn.rs +++ b/src/doc_examples/spawn.rs @@ -1,7 +1,8 @@ -#![allow(non_snake_case, unused)] +#![allow(unused)] use dioxus::prelude::*; +#[component] pub fn App(cx: Scope) -> Element { // ANCHOR: spawn let logged_in = use_state(cx, || false); @@ -41,6 +42,7 @@ pub fn App(cx: Scope) -> Element { } #[cfg(feature = "doc_test")] +#[component] pub fn Tokio(cx: Scope) -> Element { let _ = || { // ANCHOR: tokio @@ -58,6 +60,7 @@ pub fn Tokio(cx: Scope) -> Element { cx.render(rsx!(())) } +#[component] pub fn ToOwnedMacro(cx: Scope) -> Element { let count = use_state(cx, || 0); let age = use_state(cx, || 0); diff --git a/src/doc_examples/use_coroutine.rs b/src/doc_examples/use_coroutine.rs index a9f0b2e76..9a662c34b 100644 --- a/src/doc_examples/use_coroutine.rs +++ b/src/doc_examples/use_coroutine.rs @@ -1,7 +1,8 @@ -#![allow(non_snake_case, unused)] +#![allow(unused)] use dioxus::prelude::*; use std::collections::HashMap; +#[component] pub fn App(cx: Scope) -> Element { // ANCHOR: use_coroutine // import futures::StreamExt to use the next() method