From e51cebbbd65622d166d1890d909e89e2ac6a3671 Mon Sep 17 00:00:00 2001 From: Muhammad Hamza Date: Wed, 9 Aug 2023 23:54:50 +0500 Subject: [PATCH] Make signature of use_future_with consistent --- packages/yew/src/suspense/hooks.rs | 4 ++-- packages/yew/tests/suspense.rs | 13 +++++-------- .../migration-guides/yew/from-0_20_0-to-next.mdx | 3 +++ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/yew/src/suspense/hooks.rs b/packages/yew/src/suspense/hooks.rs index 04a5e51c722..b31a57663d6 100644 --- a/packages/yew/src/suspense/hooks.rs +++ b/packages/yew/src/suspense/hooks.rs @@ -72,7 +72,7 @@ where T: Future + 'static, O: 'static, { - use_future_with_deps(move |_| init_f(), ()) + use_future_with((), move |_| init_f()) } /// Use the result of an async computation with dependencies, suspending while waiting. @@ -84,7 +84,7 @@ where /// /// [ready]: std::task::Poll::Ready #[hook] -pub fn use_future_with_deps(f: F, deps: D) -> SuspensionResult> +pub fn use_future_with(deps: D, f: F) -> SuspensionResult> where F: FnOnce(Rc) -> T, T: Future + 'static, diff --git a/packages/yew/tests/suspense.rs b/packages/yew/tests/suspense.rs index cc3f0bf7e10..0596f3c6946 100644 --- a/packages/yew/tests/suspense.rs +++ b/packages/yew/tests/suspense.rs @@ -13,7 +13,7 @@ use web_sys::{HtmlElement, HtmlTextAreaElement}; use yew::platform::spawn_local; use yew::platform::time::sleep; use yew::prelude::*; -use yew::suspense::{use_future, use_future_with_deps, Suspension, SuspensionResult}; +use yew::suspense::{use_future, use_future_with, Suspension, SuspensionResult}; use yew::UseStateHandle; wasm_bindgen_test_configure!(run_in_browser); @@ -645,13 +645,10 @@ async fn use_suspending_future_with_deps_works() { #[function_component(Content)] fn content(ContentProps { delay_millis }: &ContentProps) -> HtmlResult { - let delayed_result = use_future_with_deps( - |delay_millis| async move { - sleep(Duration::from_millis(*delay_millis)).await; - 42 - }, - *delay_millis, - )?; + let delayed_result = use_future_with(*delay_millis, |delay_millis| async move { + sleep(Duration::from_millis(*delay_millis)).await; + 42 + })?; Ok(html! {
diff --git a/website/docs/migration-guides/yew/from-0_20_0-to-next.mdx b/website/docs/migration-guides/yew/from-0_20_0-to-next.mdx index c288cfc9285..c7f8c275694 100644 --- a/website/docs/migration-guides/yew/from-0_20_0-to-next.mdx +++ b/website/docs/migration-guides/yew/from-0_20_0-to-next.mdx @@ -24,6 +24,9 @@ sg --pattern 'use_callback($DEPENDENCIES,,$$$CALLBACK)' --rewrite 'use_callback( sg --pattern 'use_memo($CALLBACK,$$$DEPENDENCIES)' --rewrite 'use_memo($$$DEPENDENCIES, $CALLBACK)' -l rs -i sg --pattern 'use_memo($DEPENDENCIES,,$$$CALLBACK)' --rewrite 'use_memo($DEPENDENCIES,$$$CALLBACK)' -l rs -i + +sg --pattern 'use_future_with_deps($CALLBACK,$$$DEPENDENCIES)' --rewrite 'use_effect_with($$$DEPENDENCIES, $CALLBACK)' -l rs -i +sg --pattern 'use_future_with($DEPENDENCIES,,$$$CALLBACK)' --rewrite 'use_effect_with($DEPENDENCIES,$$$CALLBACK)' -l rs -i ``` ### Reasoning