From 3866aa297752df2f1ccd38181c8c580e037906fc Mon Sep 17 00:00:00 2001 From: Evan Almloff Date: Wed, 13 Mar 2024 10:03:00 -0500 Subject: [PATCH] simplify use_dependencies docs --- packages/hooks/src/use_effect.rs | 18 ++++-------------- packages/hooks/src/use_resource.rs | 13 ++----------- packages/signals/src/memo.rs | 4 ++-- 3 files changed, 8 insertions(+), 27 deletions(-) diff --git a/packages/hooks/src/use_effect.rs b/packages/hooks/src/use_effect.rs index 0bec415bc..dd7a303cc 100644 --- a/packages/hooks/src/use_effect.rs +++ b/packages/hooks/src/use_effect.rs @@ -65,23 +65,13 @@ impl Effect { /// /// #[component] /// fn Comp(delay: u32) -> Element { - /// // Because the resource subscribes to `delay` by adding it as a dependency, the effect's closure will rerun every time `delay` changes. - /// let current_weather = use_resource(move || async move { - /// sleep(delay).await; - /// "Sunny" + /// // Because the effect subscribes to `delay` by adding it as a dependency, the effect's closure will rerun every time `delay` changes. + /// use_effect(move || { + /// println!("It is safe to manually manipulate the dom here"); /// }) /// .use_dependencies((&delay,)); /// - /// rsx! { - /// // the value of the resource can be polled to - /// // conditionally render elements based off if it's future - /// // finished (Some(Ok(_)), errored Some(Err(_)), - /// // or is still running (None) - /// match &*current_weather.read_unchecked() { - /// Some(weather) => rsx! { "{weather}" }, - /// None => rsx! { p { "Loading..." } } - /// } - /// } + /// todo!() /// } /// ``` pub fn use_dependencies(mut self, dependency: impl Dependency) -> Self { diff --git a/packages/hooks/src/use_resource.rs b/packages/hooks/src/use_resource.rs index 1276c5398..ac60ccb6c 100644 --- a/packages/hooks/src/use_resource.rs +++ b/packages/hooks/src/use_resource.rs @@ -23,7 +23,7 @@ use std::{cell::Cell, future::Future, rc::Rc}; /// }); /// /// // Because the resource's future subscribes to `country` by reading it (`country.read()`), -/// // everytime `country` changes the resource's future will run again and thus provide a new value. +/// // every time `country` changes the resource's future will run again and thus provide a new value. /// let current_weather = use_resource(move || async move { get_weather(&country.read().clone()).await }); /// /// rsx! { @@ -144,16 +144,7 @@ impl Resource { /// }) /// .use_dependencies((&delay,)); /// - /// rsx! { - /// // the value of the resource can be polled to - /// // conditionally render elements based off if it's future - /// // finished (Some(Ok(_)), errored Some(Err(_)), - /// // or is still running (None) - /// match &*current_weather.read_unchecked() { - /// Some(weather) => rsx! { "{weather}" }, - /// None => rsx! { p { "Loading..." } } - /// } - /// } + /// todo!() /// } /// ``` pub fn use_dependencies(mut self, dependency: impl Dependency) -> Self { diff --git a/packages/signals/src/memo.rs b/packages/signals/src/memo.rs index 18e235af8..8d60dd9f0 100644 --- a/packages/signals/src/memo.rs +++ b/packages/signals/src/memo.rs @@ -166,8 +166,8 @@ impl Memo { /// /// #[component] /// fn Comp(count: u32) -> Element { - /// // Because the resource subscribes to `delay` by adding it as a dependency, the memo will rerun every time `count` changes. - /// let new_count = use_memo(move || async move { + /// // Because the memo subscribes to `count` by adding it as a dependency, the memo will rerun every time `count` changes. + /// let new_count = use_memo(move || { /// count + 1 /// }) /// .use_dependencies((&count,));