mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
initial work updating suspense tests
This commit is contained in:
parent
faa481f2b6
commit
fa8bb15a67
4 changed files with 78 additions and 57 deletions
|
@ -10,18 +10,16 @@ crate-type = ["cdylib", "rlib"]
|
|||
actix-files = { version = "0.6", optional = true }
|
||||
actix-web = { version = "4", optional = true, features = ["macros"] }
|
||||
console_error_panic_hook = "0.1"
|
||||
console_log = "1"
|
||||
leptos = { path = "../../leptos", features = ["serde"] }
|
||||
leptos = { path = "../../leptos" }
|
||||
leptos_actix = { path = "../../integrations/actix", optional = true }
|
||||
leptos_router = { path = "../../router" }
|
||||
log = "0.4"
|
||||
simple_logger = "4"
|
||||
wasm-bindgen = "0.2"
|
||||
serde = "1.0.159"
|
||||
tokio = { version = "1.29", features = ["time", "rt"], optional = true }
|
||||
|
||||
[features]
|
||||
hydrate = ["leptos/hydrate", "leptos_router/hydrate"]
|
||||
hydrate = ["leptos/hydrate"]
|
||||
ssr = [
|
||||
"dep:actix-files",
|
||||
"dep:actix-web",
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
use leptos::prelude::*;
|
||||
use leptos_router::*;
|
||||
use leptos::{logging, prelude::*};
|
||||
use leptos_router::{
|
||||
components::{Outlet, ParentRoute, Redirect, Route, Router, Routes, A},
|
||||
SsrMode, StaticSegment,
|
||||
};
|
||||
|
||||
const WAIT_ONE_SECOND: u64 = 1;
|
||||
const WAIT_TWO_SECONDS: u64 = 2;
|
||||
|
@ -32,7 +35,6 @@ pub fn App() -> impl IntoView {
|
|||
}
|
||||
";
|
||||
view! {
|
||||
|
||||
<style>{style}</style>
|
||||
<Router>
|
||||
<nav>
|
||||
|
@ -41,30 +43,30 @@ pub fn App() -> impl IntoView {
|
|||
<A href="/async">"Async"</A>
|
||||
</nav>
|
||||
<main>
|
||||
<Routes>
|
||||
<Routes fallback=|| "Page not found.">
|
||||
<Route
|
||||
path=""
|
||||
path=StaticSegment("")
|
||||
view=|| view! { <Redirect path="/out-of-order"/> }
|
||||
/>
|
||||
// out-of-order
|
||||
<Route
|
||||
path="out-of-order"
|
||||
<ParentRoute
|
||||
path=StaticSegment("out-of-order")
|
||||
view=|| view! {
|
||||
<SecondaryNav/>
|
||||
<h1>"Out-of-Order"</h1>
|
||||
<Outlet/>
|
||||
}
|
||||
>
|
||||
<Route path="" view=Nested/>
|
||||
<Route path="inside" view=NestedResourceInside/>
|
||||
<Route path="single" view=Single/>
|
||||
<Route path="parallel" view=Parallel/>
|
||||
<Route path="inside-component" view=InsideComponent/>
|
||||
<Route path="none" view=None/>
|
||||
</Route>
|
||||
<Route path=StaticSegment("") view=Nested/>
|
||||
<Route path=StaticSegment("inside") view=NestedResourceInside/>
|
||||
<Route path=StaticSegment("single") view=Single/>
|
||||
<Route path=StaticSegment("parallel") view=Parallel/>
|
||||
<Route path=StaticSegment("inside-component") view=InsideComponent/>
|
||||
<Route path=StaticSegment("none") view=None/>
|
||||
</ParentRoute>
|
||||
// in-order
|
||||
<Route
|
||||
path="in-order"
|
||||
<ParentRoute
|
||||
path=StaticSegment("in-order")
|
||||
ssr=SsrMode::InOrder
|
||||
view=|| view! {
|
||||
<SecondaryNav/>
|
||||
|
@ -72,16 +74,16 @@ pub fn App() -> impl IntoView {
|
|||
<Outlet/>
|
||||
}
|
||||
>
|
||||
<Route path="" view=Nested/>
|
||||
<Route path="inside" view=NestedResourceInside/>
|
||||
<Route path="single" view=Single/>
|
||||
<Route path="parallel" view=Parallel/>
|
||||
<Route path="inside-component" view=InsideComponent/>
|
||||
<Route path="none" view=None/>
|
||||
</Route>
|
||||
<Route path=StaticSegment("") view=Nested/>
|
||||
<Route path=StaticSegment("inside") view=NestedResourceInside/>
|
||||
<Route path=StaticSegment("single") view=Single/>
|
||||
<Route path=StaticSegment("parallel") view=Parallel/>
|
||||
<Route path=StaticSegment("inside-component") view=InsideComponent/>
|
||||
<Route path=StaticSegment("none") view=None/>
|
||||
</ParentRoute>
|
||||
// async
|
||||
<Route
|
||||
path="async"
|
||||
<ParentRoute
|
||||
path=StaticSegment("async")
|
||||
ssr=SsrMode::Async
|
||||
view=|| view! {
|
||||
<SecondaryNav/>
|
||||
|
@ -89,13 +91,13 @@ pub fn App() -> impl IntoView {
|
|||
<Outlet/>
|
||||
}
|
||||
>
|
||||
<Route path="" view=Nested/>
|
||||
<Route path="inside" view=NestedResourceInside/>
|
||||
<Route path="single" view=Single/>
|
||||
<Route path="parallel" view=Parallel/>
|
||||
<Route path="inside-component" view=InsideComponent/>
|
||||
<Route path="none" view=None/>
|
||||
</Route>
|
||||
<Route path=StaticSegment("") view=Nested/>
|
||||
<Route path=StaticSegment("inside") view=NestedResourceInside/>
|
||||
<Route path=StaticSegment("single") view=Single/>
|
||||
<Route path=StaticSegment("parallel") view=Parallel/>
|
||||
<Route path=StaticSegment("inside-component") view=InsideComponent/>
|
||||
<Route path=StaticSegment("none") view=None/>
|
||||
</ParentRoute>
|
||||
</Routes>
|
||||
</main>
|
||||
</Router>
|
||||
|
@ -118,9 +120,9 @@ fn SecondaryNav() -> impl IntoView {
|
|||
|
||||
#[component]
|
||||
fn Nested() -> impl IntoView {
|
||||
let one_second = create_resource(|| WAIT_ONE_SECOND, first_wait_fn);
|
||||
let two_second = create_resource(|| WAIT_TWO_SECONDS, second_wait_fn);
|
||||
let (count, set_count) = create_signal(0);
|
||||
let one_second = Resource::new_serde(|| WAIT_ONE_SECOND, first_wait_fn);
|
||||
let two_second = Resource::new_serde(|| WAIT_TWO_SECONDS, second_wait_fn);
|
||||
let (count, set_count) = signal(0);
|
||||
|
||||
view! {
|
||||
<div>
|
||||
|
@ -147,15 +149,15 @@ fn Nested() -> impl IntoView {
|
|||
|
||||
#[component]
|
||||
fn NestedResourceInside() -> impl IntoView {
|
||||
let one_second = create_resource(|| WAIT_ONE_SECOND, first_wait_fn);
|
||||
let (count, set_count) = create_signal(0);
|
||||
let one_second = Resource::new_serde(|| WAIT_ONE_SECOND, first_wait_fn);
|
||||
let (count, set_count) = signal(0);
|
||||
|
||||
view! {
|
||||
<div>
|
||||
<Suspense fallback=|| "Loading 1...">
|
||||
{move || {
|
||||
one_second.get().map(|_| {
|
||||
let two_second = create_resource(|| (), move |_| async move {
|
||||
let two_second = Resource::new_serde(|| (), move |_| async move {
|
||||
logging::log!("creating two_second resource");
|
||||
second_wait_fn(WAIT_TWO_SECONDS).await
|
||||
});
|
||||
|
@ -185,9 +187,9 @@ fn NestedResourceInside() -> impl IntoView {
|
|||
|
||||
#[component]
|
||||
fn Parallel() -> impl IntoView {
|
||||
let one_second = create_resource(|| WAIT_ONE_SECOND, first_wait_fn);
|
||||
let two_second = create_resource(|| WAIT_TWO_SECONDS, second_wait_fn);
|
||||
let (count, set_count) = create_signal(0);
|
||||
let one_second = Resource::new_serde(|| WAIT_ONE_SECOND, first_wait_fn);
|
||||
let two_second = Resource::new_serde(|| WAIT_TWO_SECONDS, second_wait_fn);
|
||||
let (count, set_count) = signal(0);
|
||||
|
||||
view! {
|
||||
<div>
|
||||
|
@ -217,8 +219,8 @@ fn Parallel() -> impl IntoView {
|
|||
|
||||
#[component]
|
||||
fn Single() -> impl IntoView {
|
||||
let one_second = create_resource(|| WAIT_ONE_SECOND, first_wait_fn);
|
||||
let (count, set_count) = create_signal(0);
|
||||
let one_second = Resource::new_serde(|| WAIT_ONE_SECOND, first_wait_fn);
|
||||
let (count, set_count) = signal(0);
|
||||
|
||||
view! {
|
||||
<div>
|
||||
|
@ -241,7 +243,7 @@ fn Single() -> impl IntoView {
|
|||
|
||||
#[component]
|
||||
fn InsideComponent() -> impl IntoView {
|
||||
let (count, set_count) = create_signal(0);
|
||||
let (count, set_count) = signal(0);
|
||||
|
||||
view! {
|
||||
<div>
|
||||
|
@ -259,7 +261,7 @@ fn InsideComponent() -> impl IntoView {
|
|||
|
||||
#[component]
|
||||
fn InsideComponentChild() -> impl IntoView {
|
||||
let one_second = create_resource(|| WAIT_ONE_SECOND, first_wait_fn);
|
||||
let one_second = Resource::new_serde(|| WAIT_ONE_SECOND, first_wait_fn);
|
||||
view! {
|
||||
<Suspense fallback=|| "Loading 1...">
|
||||
{move || {
|
||||
|
@ -273,7 +275,7 @@ fn InsideComponentChild() -> impl IntoView {
|
|||
|
||||
#[component]
|
||||
fn None() -> impl IntoView {
|
||||
let (count, set_count) = create_signal(0);
|
||||
let (count, set_count) = signal(0);
|
||||
|
||||
view! {
|
||||
<div>
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
pub mod app;
|
||||
|
||||
#[cfg(feature = "hydrate")]
|
||||
#[wasm_bindgen::prelude::wasm_bindgen]
|
||||
pub fn hydrate() {
|
||||
use app::*;
|
||||
|
||||
// initializes logging using the `log` crate
|
||||
_ = console_log::init_with_level(log::Level::Debug);
|
||||
console_error_panic_hook::set_once();
|
||||
|
||||
leptos::mount_to_body(App);
|
||||
leptos::mount::hydrate_body(App);
|
||||
}
|
||||
|
|
|
@ -9,17 +9,39 @@ async fn main() -> std::io::Result<()> {
|
|||
|
||||
let conf = get_configuration(None).await.unwrap();
|
||||
let addr = conf.leptos_options.site_addr;
|
||||
// Generate the list of routes in your Leptos App
|
||||
let routes = generate_route_list(App);
|
||||
println!("listening on http://{}", &addr);
|
||||
|
||||
HttpServer::new(move || {
|
||||
// Generate the list of routes in your Leptos App
|
||||
let routes = generate_route_list(App);
|
||||
let leptos_options = &conf.leptos_options;
|
||||
let site_root = &leptos_options.site_root;
|
||||
|
||||
App::new()
|
||||
.leptos_routes(leptos_options.to_owned(), routes.to_owned(), App)
|
||||
.leptos_routes(routes, {
|
||||
let leptos_options = leptos_options.clone();
|
||||
move || {
|
||||
use leptos::prelude::*;
|
||||
|
||||
view! {
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8"/>
|
||||
<meta
|
||||
name="viewport"
|
||||
content="width=device-width, initial-scale=1"
|
||||
/>
|
||||
<AutoReload options=leptos_options.clone()/>
|
||||
<HydrationScripts options=leptos_options.clone()/>
|
||||
</head>
|
||||
<body>
|
||||
<App/>
|
||||
</body>
|
||||
</html>
|
||||
}
|
||||
}})
|
||||
.service(Files::new("/", site_root))
|
||||
//.wrap(middleware::Compress::default())
|
||||
})
|
||||
.bind(addr)?
|
||||
.workers(1)
|
||||
|
|
Loading…
Reference in a new issue