Skip to content

Commit

Permalink
Make signature of use_future_with consistent (#3372)
Browse files Browse the repository at this point in the history
  • Loading branch information
ranile authored Aug 15, 2023
1 parent e59edde commit 41d42fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
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

0 comments on commit 41d42fb

Please sign in to comment.