Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make signature of use_future_with consistent #3372

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/yew/src/suspense/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where
T: Future<Output = O> + '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.
Expand All @@ -84,7 +84,7 @@ where
///
/// [ready]: std::task::Poll::Ready
#[hook]
pub fn use_future_with_deps<F, D, T, O>(f: F, deps: D) -> SuspensionResult<UseFutureHandle<O>>
pub fn use_future_with<F, D, T, O>(deps: D, f: F) -> SuspensionResult<UseFutureHandle<O>>
where
F: FnOnce(Rc<D>) -> T,
T: Future<Output = O> + 'static,
Expand Down
13 changes: 5 additions & 8 deletions packages/yew/tests/suspense.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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! {
<div>
Expand Down
3 changes: 3 additions & 0 deletions website/docs/migration-guides/yew/from-0_20_0-to-next.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading