Chore: hoist example projects for discoverability (#2959)
* hoist example projects, remove oidc * move over example projects from the separate repo * Update ecommerce site to the latest version of dioxus * update wifi scanner to 0.5 * drop the chatbot example; might be restored in a separate PR --------- Co-authored-by: Evan Almloff <evanalmloff@gmail.com>
This commit is contained in:
1 parent
a9f87384f8
commit
983fcfc616
94 files changed
+2774
-7322
No files matched your search
@@ -1,207 +0,0 @@
|
||||
#![allow(unused)]
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use dioxus::prelude::*;
|
||||
use dioxus_router::prelude::*;
|
||||
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
|
||||
use dioxus_ssr::Renderer;
|
||||
|
||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
c.bench_function("build 1000 routes", |b| {
|
||||
let mut renderer = IncrementalRenderer::builder()
|
||||
.static_dir("./static")
|
||||
.invalidate_after(Duration::from_secs(10))
|
||||
.build();
|
||||
let wrapper = DefaultRenderer {
|
||||
before_body: r#"<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width,
|
||||
initial-scale=1.0">
|
||||
<title>Dioxus Application</title>
|
||||
</head>
|
||||
<body>"#
|
||||
.to_string(),
|
||||
after_body: r#"</body>
|
||||
</html>"#
|
||||
.to_string(),
|
||||
};
|
||||
|
||||
b.iter(|| {
|
||||
tokio::runtime::Runtime::new().unwrap().block_on(async {
|
||||
for id in 0..1000 {
|
||||
render_route(
|
||||
&mut renderer,
|
||||
Route::Post { id },
|
||||
&mut tokio::io::sink(),
|
||||
|_| Box::pin(async move {}),
|
||||
&wrapper,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
})
|
||||
})
|
||||
});
|
||||
|
||||
c.bench_function("build 1000 routes no memory cache", |b| {
|
||||
let wrapper = DefaultRenderer {
|
||||
before_body: r#"<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width,
|
||||
initial-scale=1.0">
|
||||
<title>Dioxus Application</title>
|
||||
</head>
|
||||
<body>"#
|
||||
.to_string(),
|
||||
after_body: r#"</body>
|
||||
</html>"#
|
||||
.to_string(),
|
||||
};
|
||||
b.to_async(tokio::runtime::Runtime::new().unwrap())
|
||||
.iter(|| async {
|
||||
let mut renderer = IncrementalRenderer::builder()
|
||||
.static_dir("./static")
|
||||
.memory_cache_limit(0)
|
||||
.invalidate_after(Duration::from_secs(10))
|
||||
.build();
|
||||
|
||||
for id in 0..1000 {
|
||||
render_route(
|
||||
&mut renderer,
|
||||
Route::Post { id },
|
||||
&mut tokio::io::sink(),
|
||||
|_| Box::pin(async move {}),
|
||||
&wrapper,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
}
|
||||
})
|
||||
});
|
||||
c.bench_function("build 1000 routes no cache", |b| {
|
||||
let mut renderer = Renderer::default();
|
||||
|
||||
b.iter(|| {
|
||||
for id in 0..1000 {
|
||||
let mut vdom = VirtualDom::new_with_props(
|
||||
RenderPath,
|
||||
RenderPathProps::builder().path(Route::Post { id }).build(),
|
||||
);
|
||||
|
||||
vdom.rebuild_in_place();
|
||||
|
||||
struct Ignore;
|
||||
|
||||
impl std::fmt::Write for Ignore {
|
||||
fn write_str(&mut self, s: &str) -> std::fmt::Result {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
renderer.render_to(&mut Ignore, &vdom).unwrap();
|
||||
}
|
||||
})
|
||||
});
|
||||
c.bench_function("cache static", |b| {
|
||||
let wrapper = DefaultRenderer {
|
||||
before_body: r#"<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width,
|
||||
initial-scale=1.0">
|
||||
<title>Dioxus Application</title>
|
||||
</head>
|
||||
<body>"#
|
||||
.to_string(),
|
||||
after_body: r#"</body>
|
||||
</html>"#
|
||||
.to_string(),
|
||||
};
|
||||
b.to_async(tokio::runtime::Runtime::new().unwrap())
|
||||
.iter(|| async {
|
||||
let mut renderer = IncrementalRenderer::builder()
|
||||
.static_dir("./static")
|
||||
.build();
|
||||
|
||||
pre_cache_static_routes::<Route, _>(&mut renderer, &wrapper)
|
||||
.await
|
||||
.unwrap();
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
criterion_group!(benches, criterion_benchmark);
|
||||
criterion_main!(benches);
|
||||
|
||||
#[component]
|
||||
fn Blog() -> Element {
|
||||
rsx! {
|
||||
div {
|
||||
"Blog"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Post(id: usize) -> Element {
|
||||
rsx! {
|
||||
for _ in 0..id {
|
||||
div {
|
||||
"PostId: {id}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn PostHome() -> Element {
|
||||
rsx! {
|
||||
div {
|
||||
"Post"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Home() -> Element {
|
||||
rsx! {
|
||||
div {
|
||||
"Home"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
#[derive(Clone, Debug, PartialEq, Routable)]
|
||||
enum Route {
|
||||
#[nest("/blog")]
|
||||
#[route("/")]
|
||||
Blog {},
|
||||
#[route("/post/index")]
|
||||
PostHome {},
|
||||
#[route("/post/:id")]
|
||||
Post {
|
||||
id: usize,
|
||||
},
|
||||
#[end_nest]
|
||||
#[route("/")]
|
||||
Home {},
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn RenderPath(path: Route) -> Element {
|
||||
let path = path.clone();
|
||||
rsx! {
|
||||
Router::<Route> {
|
||||
config: || RouterConfig::default().history(MemoryHistory::with_initial_path(path))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
dist
|
||||
target
|
||||
docs
|
||||
.dioxus
|
||||
@@ -1,17 +0,0 @@
|
||||
[package]
|
||||
name = "github-pages-static-generation"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dioxus = { workspace = true, features = ["static-generation", "router"] }
|
||||
tower = { workspace = true, features = ["util"] }
|
||||
tracing-subscriber = "0.3.18"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
server = ["dioxus/axum"]
|
||||
web = ["dioxus/web"]
|
||||
@@ -1,70 +0,0 @@
|
||||
//! You can use the `github_pages` method to set up a preset for github pages.
|
||||
//! This will output your files in the `/docs` directory and set up a `404.html` file.
|
||||
|
||||
#![allow(unused)]
|
||||
use dioxus::prelude::*;
|
||||
|
||||
// Generate all routes and output them to the static path
|
||||
fn main() {
|
||||
LaunchBuilder::new()
|
||||
.with_cfg(dioxus::static_site_generation::Config::new().github_pages())
|
||||
.launch(|| {
|
||||
rsx! {
|
||||
Router::<Route> {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Clone, Routable, Debug, PartialEq)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Home {},
|
||||
|
||||
#[route("/blog")]
|
||||
Blog,
|
||||
|
||||
// You must include a catch all route to handle 404s
|
||||
#[route("/:..route")]
|
||||
PageNotFound { route: Vec<String> },
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Blog() -> Element {
|
||||
rsx! {
|
||||
Link { to: Route::Home {}, "Go to counter" }
|
||||
table {
|
||||
tbody {
|
||||
for _ in 0..100 {
|
||||
tr {
|
||||
for _ in 0..100 {
|
||||
td { "hello world!" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Home() -> Element {
|
||||
let mut count = use_signal(|| 0);
|
||||
|
||||
rsx! {
|
||||
Link { to: Route::Blog {}, "Go to blog" }
|
||||
div {
|
||||
h1 { "High-Five counter: {count}" }
|
||||
button { onclick: move |_| count += 1, "Up high!" }
|
||||
button { onclick: move |_| count -= 1, "Down low!" }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn PageNotFound(route: Vec<String>) -> Element {
|
||||
rsx! {
|
||||
h1 { "Page not found" }
|
||||
p { "We are terribly sorry, but the page you requested doesn't exist." }
|
||||
pre { color: "red", "log:\nattempted to navigate to: {route:?}" }
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
dist
|
||||
target
|
||||
static
|
||||
.dioxus
|
||||
@@ -1,16 +0,0 @@
|
||||
[package]
|
||||
name = "router-static-generation"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dioxus = { workspace = true, features = ["static-generation", "router"] }
|
||||
tracing-subscriber = "0.3.18"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
server = ["dioxus/axum"]
|
||||
web = ["dioxus/web"]
|
||||
@@ -1,54 +0,0 @@
|
||||
//! Static generation works out of the box with the router. Just add a router anywhere in your app and it will generate any static routes for you!
|
||||
|
||||
#![allow(unused)]
|
||||
use dioxus::prelude::*;
|
||||
|
||||
// Generate all routes and output them to the static path
|
||||
fn main() {
|
||||
launch(|| {
|
||||
rsx! {
|
||||
Router::<Route> {}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[derive(Clone, Routable, Debug, PartialEq)]
|
||||
enum Route {
|
||||
#[route("/")]
|
||||
Home {},
|
||||
|
||||
#[route("/blog")]
|
||||
Blog,
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Blog() -> Element {
|
||||
rsx! {
|
||||
Link { to: Route::Home {}, "Go to counter" }
|
||||
table {
|
||||
tbody {
|
||||
for _ in 0..100 {
|
||||
tr {
|
||||
for _ in 0..100 {
|
||||
td { "hello!" }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn Home() -> Element {
|
||||
let mut count = use_signal(|| 0);
|
||||
|
||||
rsx! {
|
||||
Link { to: Route::Blog {}, "Go to blog" }
|
||||
div {
|
||||
h1 { "High-Five counter: {count}" }
|
||||
button { onclick: move |_| count += 1, "Up high!" }
|
||||
button { onclick: move |_| count -= 1, "Down low!" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
dist
|
||||
target
|
||||
static
|
||||
.dioxus
|
||||
@@ -1,16 +0,0 @@
|
||||
[package]
|
||||
name = "simple-static-generation"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
dioxus = { workspace = true, features = ["static-generation"] }
|
||||
tracing-subscriber = "0.3.18"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
server = ["dioxus/axum"]
|
||||
web = ["dioxus/web"]
|
||||
@@ -1,17 +0,0 @@
|
||||
//! Static generation lets you pre-render your entire app to static files and then hydrate it on the client.
|
||||
use dioxus::prelude::*;
|
||||
|
||||
// Generate all routes and output them to the static path
|
||||
fn main() {
|
||||
launch(app);
|
||||
}
|
||||
|
||||
fn app() -> Element {
|
||||
let mut count = use_signal(|| 0);
|
||||
|
||||
rsx! {
|
||||
h1 { "High-Five counter: {count}" }
|
||||
button { onclick: move |_| count += 1, "Up high!" }
|
||||
button { onclick: move |_| count -= 1, "Down low!" }
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user