From 4a4b1bdf5ce7e6736fadd59a3cde9dfd7b433c99 Mon Sep 17 00:00:00 2001 From: luoxiao Date: Tue, 6 Aug 2024 10:59:34 +0800 Subject: [PATCH] feat: optimized routing --- demo/src/app.rs | 195 +++++++++++----------- demo_markdown/docs/_guide/installation.md | 8 +- 2 files changed, 100 insertions(+), 103 deletions(-) diff --git a/demo/src/app.rs b/demo/src/app.rs index 5ea61e6..24be698 100644 --- a/demo/src/app.rs +++ b/demo/src/app.rs @@ -13,106 +13,7 @@ use thaw::*; #[component] pub fn App() -> impl IntoView { - let is_routing = RwSignal::new(false); - let set_is_routing = SignalSetter::map(move |is_routing_data| { - is_routing.set(is_routing_data); - }); provide_meta_context(); - - view! { - - - - - - } -} - -#[component] -fn TheRouter(is_routing: RwSignal) -> impl IntoView { - let loading_bar = LoadingBarInjection::expect_use(); - _ = is_routing.watch(move |is_routing| { - if *is_routing { - loading_bar.start(); - } else { - loading_bar.finish(); - } - }); - - view! { - - - - - - - - - { - view! { - - - - - - - - - - - - - - - } - } - { - view! { - - - - - - - - - - - - - - - - - } - } - { - view! { - - - - - - - - - - - - - - - - - } - } - - - } -} - -#[component] -fn TheProvider(children: Children) -> impl IntoView { // let (read_theme, _, _) = use_local_storage::("theme"); // let theme = RwSignal::new(Theme::from(read_theme.get_untracked())); @@ -120,9 +21,103 @@ fn TheProvider(children: Children) -> impl IntoView { - {children()} + } } + +#[component] +fn TheRouter() -> impl IntoView { + let loading_bar = LoadingBarInjection::expect_use(); + let is_routing = RwSignal::new(false); + let set_is_routing = SignalSetter::map(move |is_routing_data| { + is_routing.set(is_routing_data); + }); + + Effect::watch( + move || is_routing.get(), + move |is_routing, _, _| { + if *is_routing { + loading_bar.start(); + } else { + loading_bar.finish(); + } + }, + false, + ); + + view! { + + + + + + + + + + { + view! { + + + + + + + + + + + + + + + } + } + { + view! { + + + + + + + + + + + + + + + + + } + } + { + view! { + + + + + + + + + + + + + + + + + } + } + + + + } +} diff --git a/demo_markdown/docs/_guide/installation.md b/demo_markdown/docs/_guide/installation.md index e23035c..68a4e27 100644 --- a/demo_markdown/docs/_guide/installation.md +++ b/demo_markdown/docs/_guide/installation.md @@ -30,9 +30,11 @@ fn main() { #[component] pub fn App() -> impl IntoView { view! { - + + + } } ``` \ No newline at end of file