From c459baf122246544b9203f83508c9deec5016c1d Mon Sep 17 00:00:00 2001 From: Marcel Date: Fri, 6 Oct 2023 19:16:48 +0200 Subject: [PATCH 1/4] Updated to yew 0.21 and gloo 0.10 --- crates/bounce/Cargo.toml | 8 ++++---- examples/divisibility-input/Cargo.toml | 6 +++--- examples/divisibility/Cargo.toml | 6 +++--- examples/helmet-ssr/Cargo.toml | 6 +++--- examples/helmet-title/Cargo.toml | 6 +++--- examples/notion/Cargo.toml | 6 +++--- examples/partial-render/Cargo.toml | 6 +++--- examples/persist/Cargo.toml | 4 ++-- examples/queries-mutations/Cargo.toml | 4 ++-- examples/queries-ssr/Cargo.toml | 4 ++-- examples/random-uuid/Cargo.toml | 4 ++-- examples/simple/Cargo.toml | 4 ++-- examples/title/Cargo.toml | 6 +++--- 13 files changed, 35 insertions(+), 35 deletions(-) diff --git a/crates/bounce/Cargo.toml b/crates/bounce/Cargo.toml index 18798f7..c9342df 100644 --- a/crates/bounce/Cargo.toml +++ b/crates/bounce/Cargo.toml @@ -16,12 +16,12 @@ rust-version = "1.64.0" anymap2 = "0.13.0" once_cell = "1.18.0" wasm-bindgen = "0.2.87" -yew = "0.20" +yew = "0.21" bounce-macros = { path = "../bounce-macros", version = "0.8.0" } futures = "0.3.28" async-trait = { version = "0.1.68", optional = true } -gloo = { version = "0.9.0", features = ["futures"], optional = true } +gloo = { version = "0.10.0", features = ["futures"], optional = true } html-escape = { version = "0.2.13", optional = true } serde = { version = "1.0.164", features = ["derive"] } tracing = "0.1" @@ -47,8 +47,8 @@ helmet = ["gloo", "web-sys"] [dev-dependencies] wasm-bindgen-test = "0.3.37" -gloo = { version = "0.9.0", features = ["futures"] } -yew = { version = "0.20", features = ["csr", "ssr"] } +gloo = { version = "0.10.0", features = ["futures"] } +yew = { version = "0.21", features = ["csr", "ssr"] } thiserror = "1" [dev-dependencies.web-sys] diff --git a/examples/divisibility-input/Cargo.toml b/examples/divisibility-input/Cargo.toml index d804e8b..b69abbc 100644 --- a/examples/divisibility-input/Cargo.toml +++ b/examples/divisibility-input/Cargo.toml @@ -8,13 +8,13 @@ publish = false [dependencies] bounce = { path = "../../crates/bounce" } -yew = { version = "0.20", features = ["csr"] } -stylist = { version = "0.12.1", features = ["yew"] } +yew = { version = "0.21", features = ["csr"] } +stylist = { version = "0.13", features = ["yew"] } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } wasm-bindgen = "0.2.87" [dev-dependencies] wasm-bindgen-test = "0.3.37" -gloo = { version = "0.9.0", features = ["futures"] } +gloo = { version = "0.10.0", features = ["futures"] } web-sys = "0.3.64" diff --git a/examples/divisibility/Cargo.toml b/examples/divisibility/Cargo.toml index 061d28a..bfdfb14 100644 --- a/examples/divisibility/Cargo.toml +++ b/examples/divisibility/Cargo.toml @@ -8,13 +8,13 @@ publish = false [dependencies] bounce = { path = "../../crates/bounce" } -yew = { version = "0.20", features = ["csr"] } -stylist = { version = "0.12.1", features = ["yew"] } +yew = { version = "0.21", features = ["csr"] } +stylist = { version = "0.13", features = ["yew"] } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } wasm-bindgen = "0.2.87" [dev-dependencies] wasm-bindgen-test = "0.3.37" -gloo = { version = "0.9.0", features = ["futures"] } +gloo = { version = "0.10.0", features = ["futures"] } web-sys = "0.3.64" diff --git a/examples/helmet-ssr/Cargo.toml b/examples/helmet-ssr/Cargo.toml index c83c256..9da0086 100644 --- a/examples/helmet-ssr/Cargo.toml +++ b/examples/helmet-ssr/Cargo.toml @@ -14,12 +14,12 @@ required-features = ["ssr"] [dependencies] bounce = { path = "../../crates/bounce", features = ["helmet"] } -yew = { version = "0.20" } +yew = { version = "0.21" } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } wasm-bindgen = "0.2.87" -yew-router = "0.17" -gloo = { version = "0.9.0", features = ["futures"] } +yew-router = "0.18" +gloo = { version = "0.10.0", features = ["futures"] } web-sys= "0.3.64" bytes = "1.4.0" diff --git a/examples/helmet-title/Cargo.toml b/examples/helmet-title/Cargo.toml index 8b75b21..8208456 100644 --- a/examples/helmet-title/Cargo.toml +++ b/examples/helmet-title/Cargo.toml @@ -8,12 +8,12 @@ publish = false [dependencies] bounce = { path = "../../crates/bounce", features = ["helmet"] } -yew = { version = "0.20", features = ["csr"] } +yew = { version = "0.21", features = ["csr"] } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } wasm-bindgen = "0.2.87" -yew-router = "0.17" -gloo = { version = "0.9.0", features = ["futures"] } +yew-router = "0.18" +gloo = { version = "0.10.0", features = ["futures"] } web-sys= "0.3.64" [dev-dependencies] diff --git a/examples/notion/Cargo.toml b/examples/notion/Cargo.toml index 0865bfc..689fba4 100644 --- a/examples/notion/Cargo.toml +++ b/examples/notion/Cargo.toml @@ -8,13 +8,13 @@ publish = false [dependencies] bounce = { path = "../../crates/bounce" } -yew = { version = "0.20", features = ["csr"] } -stylist = { version = "0.12.1", features = ["yew"] } +yew = { version = "0.21", features = ["csr"] } +stylist = { version = "0.13", features = ["yew"] } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } wasm-bindgen = "0.2.87" [dev-dependencies] wasm-bindgen-test = "0.3.37" -gloo = { version = "0.9.0", features = ["futures"] } +gloo = { version = "0.10.0", features = ["futures"] } web-sys = "0.3.64" diff --git a/examples/partial-render/Cargo.toml b/examples/partial-render/Cargo.toml index 70219a7..4575b76 100644 --- a/examples/partial-render/Cargo.toml +++ b/examples/partial-render/Cargo.toml @@ -8,13 +8,13 @@ publish = false [dependencies] bounce = { path = "../../crates/bounce" } -yew = { version = "0.20", features = ["csr"] } -stylist = { version = "0.12.1", features = ["yew"] } +yew = { version = "0.21", features = ["csr"] } +stylist = { version = "0.13", features = ["yew"] } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } wasm-bindgen = "0.2.87" [dev-dependencies] wasm-bindgen-test = "0.3.37" -gloo = { version = "0.9.0", features = ["futures"] } +gloo = { version = "0.10.0", features = ["futures"] } web-sys = "0.3.64" diff --git a/examples/persist/Cargo.toml b/examples/persist/Cargo.toml index 32b8801..8881788 100644 --- a/examples/persist/Cargo.toml +++ b/examples/persist/Cargo.toml @@ -8,11 +8,11 @@ publish = false [dependencies] bounce = { path = "../../crates/bounce" } -yew = { version = "0.20", features = ["csr"] } +yew = { version = "0.21", features = ["csr"] } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } wasm-bindgen = "0.2.87" -gloo = { version = "0.9.0", features = ["futures"] } +gloo = { version = "0.10.0", features = ["futures"] } [dependencies.web-sys] version = "0.3.64" diff --git a/examples/queries-mutations/Cargo.toml b/examples/queries-mutations/Cargo.toml index ad19dcf..b10c2b1 100644 --- a/examples/queries-mutations/Cargo.toml +++ b/examples/queries-mutations/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] bounce = { path = "../../crates/bounce", features = ["query"] } -yew = { version = "0.20", features = ["csr"] } +yew = { version = "0.21", features = ["csr"] } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } reqwest = { version = "0.11.18", features = ["json"] } @@ -25,4 +25,4 @@ features = [ [dev-dependencies] wasm-bindgen-test = "0.3.37" -gloo = { version = "0.9.0", features = ["futures"] } +gloo = { version = "0.10.0", features = ["futures"] } diff --git a/examples/queries-ssr/Cargo.toml b/examples/queries-ssr/Cargo.toml index 9cf7d78..2213e05 100644 --- a/examples/queries-ssr/Cargo.toml +++ b/examples/queries-ssr/Cargo.toml @@ -16,7 +16,7 @@ required-features = ["ssr"] [dependencies] bounce = { path = "../../crates/bounce", features = ["query"] } -yew = { version = "0.20" } +yew = { version = "0.21" } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } reqwest = { version = "0.11.18", features = ["json"] } @@ -42,7 +42,7 @@ html_parser = "0.7.0" [dev-dependencies] wasm-bindgen-test = "0.3.37" -gloo = { version = "0.9.0", features = ["futures"] } +gloo = { version = "0.10.0", features = ["futures"] } [features] csr = ["yew/csr", "yew/hydration"] diff --git a/examples/random-uuid/Cargo.toml b/examples/random-uuid/Cargo.toml index 8adc9ba..454ee58 100644 --- a/examples/random-uuid/Cargo.toml +++ b/examples/random-uuid/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] bounce = { path = "../../crates/bounce" } -yew = { version = "0.20", features = ["csr"] } +yew = { version = "0.21", features = ["csr"] } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } reqwest = { version = "0.11.18", features = ["json"] } @@ -23,4 +23,4 @@ features = [ [dev-dependencies] wasm-bindgen-test = "0.3.37" -gloo = { version = "0.9.0", features = ["futures"] } +gloo = { version = "0.10.0", features = ["futures"] } diff --git a/examples/simple/Cargo.toml b/examples/simple/Cargo.toml index 38f4a19..c6b0ede 100644 --- a/examples/simple/Cargo.toml +++ b/examples/simple/Cargo.toml @@ -8,7 +8,7 @@ publish = false [dependencies] bounce = { path = "../../crates/bounce" } -yew = { version = "0.20", features = ["csr"] } +yew = { version = "0.21", features = ["csr"] } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } wasm-bindgen = "0.2.87" @@ -21,4 +21,4 @@ features = [ [dev-dependencies] wasm-bindgen-test = "0.3.37" -gloo = { version = "0.9.0", features = ["futures"] } +gloo = { version = "0.10.0", features = ["futures"] } diff --git a/examples/title/Cargo.toml b/examples/title/Cargo.toml index f17daf7..678e7d9 100644 --- a/examples/title/Cargo.toml +++ b/examples/title/Cargo.toml @@ -8,12 +8,12 @@ publish = false [dependencies] bounce = { path = "../../crates/bounce" } -yew = { version = "0.20", features = ["csr"] } +yew = { version = "0.21", features = ["csr"] } log = "0.4.19" console_log = { version = "1.0.0", features = ["color"] } wasm-bindgen = "0.2.87" -yew-router = "0.17" -gloo = { version = "0.9.0", features = ["futures"] } +yew-router = "0.18" +gloo = { version = "0.10.0", features = ["futures"] } web-sys= "0.3.64" [dev-dependencies] From 62d4f87b462c6abf63444fcbe2da7b897ca91179 Mon Sep 17 00:00:00 2001 From: Marcel Date: Fri, 6 Oct 2023 19:17:26 +0200 Subject: [PATCH 2/4] Updated function signatures for yew 0.21 --- crates/bounce/src/helmet/bridge.rs | 52 ++++++------ crates/bounce/src/provider.rs | 54 ++++++------- crates/bounce/src/query/use_mutation.rs | 40 ++++------ crates/bounce/src/query/use_prepared_query.rs | 80 +++++++++---------- crates/bounce/src/query/use_query.rs | 52 ++++++------ crates/bounce/src/query/use_query_value.rs | 25 +++--- crates/bounce/src/states/artifact.rs | 33 +++----- crates/bounce/src/states/input_selector.rs | 29 +++---- crates/bounce/src/states/slice.rs | 25 +++--- crates/bounce/tests/notion.rs | 13 ++- crates/bounce/tests/query.rs | 21 +++-- examples/title/src/main.rs | 13 ++- 12 files changed, 190 insertions(+), 247 deletions(-) diff --git a/crates/bounce/src/helmet/bridge.rs b/crates/bounce/src/helmet/bridge.rs index 5fa0954..5ab66f2 100644 --- a/crates/bounce/src/helmet/bridge.rs +++ b/crates/bounce/src/helmet/bridge.rs @@ -65,16 +65,13 @@ mod guard { let guard = use_slice::(); let root = use_context::().expect_throw("No bounce root found."); - use_effect_with_deps( - move |_| { - guard.dispatch(HelmetBridgeGuardAction::Increment); + use_effect_with(root, move |_| { + guard.dispatch(HelmetBridgeGuardAction::Increment); - move || { - guard.dispatch(HelmetBridgeGuardAction::Decrement); - } - }, - root, - ); + move || { + guard.dispatch(HelmetBridgeGuardAction::Decrement); + } + }); } } @@ -244,24 +241,26 @@ pub fn helmet_bridge(props: &HelmetBridgeProps) -> Html { } // Remove pre-rendered tags. - use_effect_with_deps( - |_| { - let pre_rendered = head() - .query_selector_all("[data-bounce-helmet=pre-render]") - .expect_throw("failed to read pre rendered tags"); - - for i in 0..pre_rendered.length() { - if let Some(m) = pre_rendered.get(i) { - if let Some(parent) = m.parent_node() { - let _ = parent.remove_child(&m); - } + use_effect_with((), |_| { + let pre_rendered = head() + .query_selector_all("[data-bounce-helmet=pre-render]") + .expect_throw("failed to read pre rendered tags"); + + for i in 0..pre_rendered.length() { + if let Some(m) = pre_rendered.get(i) { + if let Some(parent) = m.parent_node() { + let _ = parent.remove_child(&m); } } - }, - (), - ); + } + }); - use_effect_with_deps( + use_effect_with( + ( + helmet_states, + props.format_title.clone(), + props.default_title.clone(), + ), move |(helmet_states, format_title, default_title)| { // Calculate tags to render. let to_render = @@ -272,11 +271,6 @@ pub fn helmet_bridge(props: &HelmetBridgeProps) -> Html { || {} }, - ( - helmet_states, - props.format_title.clone(), - props.default_title.clone(), - ), ); Html::default() diff --git a/crates/bounce/src/provider.rs b/crates/bounce/src/provider.rs index e03fc0c..3a9f535 100644 --- a/crates/bounce/src/provider.rs +++ b/crates/bounce/src/provider.rs @@ -56,45 +56,39 @@ pub fn bounce_root(props: &BounceRootProps) -> Html { #[allow(clippy::redundant_clone)] { let root_state = root_state.clone(); - use_effect_with_deps( - move |_| { - // We clear all states manually. - move || { - root_state.clear(); - } - }, - (), - ); + use_effect_with((), move |_| { + // We clear all states manually. + move || { + root_state.clear(); + } + }); } #[allow(clippy::unused_unit, clippy::redundant_clone)] { let _root_state = root_state.clone(); - let _ = use_transitive_state!( - move |_| -> () { - #[cfg(feature = "ssr")] - #[cfg(feature = "helmet")] - { - // Workaround to send helmet states back to static writer - use crate::helmet::StaticWriterState; + let _ = use_transitive_state!((), move |_| -> () { + #[cfg(feature = "ssr")] + #[cfg(feature = "helmet")] + { + // Workaround to send helmet states back to static writer + use crate::helmet::StaticWriterState; - let states = _root_state.states(); - let writer_state = states.get_atom_value::(); + let states = _root_state.states(); + let writer_state = states.get_atom_value::(); - if let Some(ref w) = writer_state.writer { - w.send_helmet( - states, - writer_state.format_title.clone(), - writer_state.default_title.clone(), - ); - } + if let Some(ref w) = writer_state.writer { + w.send_helmet( + states, + writer_state.format_title.clone(), + writer_state.default_title.clone(), + ); } + } - // We drop the root state on SSR as well. - _root_state.clear(); - }, - () - ); + // We drop the root state on SSR as well. + _root_state.clear(); + }); } html! { diff --git a/crates/bounce/src/query/use_mutation.rs b/crates/bounce/src/query/use_mutation.rs index 6e66df7..2e4ba2c 100644 --- a/crates/bounce/src/query/use_mutation.rs +++ b/crates/bounce/src/query/use_mutation.rs @@ -225,38 +225,32 @@ pub fn use_mutation() -> UseMutationHandle where T: Mutation + 'static, { - let id = *use_memo(|_| HandleId::default(), ()); + let id = *use_memo((), |_| HandleId::default()); let dispatch_state = use_slice_dispatch::>(); let run_mutation = use_future_notion_runner::>(); let state = use_input_selector_value::>(id.into()); { - use_effect_with_deps( - |id| { - let id = *id; - dispatch_state(MutationSliceAction::Create(id)); + use_effect_with(id, |id| { + let id = *id; + dispatch_state(MutationSliceAction::Create(id)); - move || { - dispatch_state(MutationSliceAction::Destroy(id)); - } - }, - id, - ); + move || { + dispatch_state(MutationSliceAction::Destroy(id)); + } + }); } - let state = use_memo( - |state| match state.value.as_ref() { - Some(MutationSliceValue::Idle) | None => MutationState::Idle, - Some(MutationSliceValue::Loading { .. }) => MutationState::Loading, - Some(MutationSliceValue::Completed { result, .. }) => MutationState::Completed { - result: result.clone(), - }, - Some(MutationSliceValue::Outdated { result, .. }) => MutationState::Refreshing { - last_result: result.clone(), - }, + let state = use_memo(state, |state| match state.value.as_ref() { + Some(MutationSliceValue::Idle) | None => MutationState::Idle, + Some(MutationSliceValue::Loading { .. }) => MutationState::Loading, + Some(MutationSliceValue::Completed { result, .. }) => MutationState::Completed { + result: result.clone(), }, - state, - ); + Some(MutationSliceValue::Outdated { result, .. }) => MutationState::Refreshing { + last_result: result.clone(), + }, + }); UseMutationHandle { id, diff --git a/crates/bounce/src/query/use_prepared_query.rs b/crates/bounce/src/query/use_prepared_query.rs index 17410dd..c38f16d 100644 --- a/crates/bounce/src/query/use_prepared_query.rs +++ b/crates/bounce/src/query/use_prepared_query.rs @@ -86,7 +86,7 @@ where T::Input: Clone + Serialize + for<'de> Deserialize<'de>, T::Error: Clone + Serialize + for<'de> Deserialize<'de>, { - let id = *use_memo(|_| Id::new(), ()); + let id = *use_memo((), |_| Id::new()); let value_state = use_input_selector_value::>(input.clone()); let dispatch_state = use_slice_dispatch::>(); let run_query = use_future_notion_runner::>(); @@ -95,8 +95,11 @@ where let _run_query = run_query.clone(); let _root = use_context::().expect_throw("No bounce root found."); - let prepared_value = use_prepared_state!( - async move |input| -> std::result::Result { + let prepared_value = + use_prepared_state!((*input).clone(), async move |input| -> std::result::Result< + T, + T::Error, + > { use std::cell::RefCell; use std::time::Duration; @@ -145,61 +148,53 @@ where } } } - }, - (*input).clone() - )?; + })?; - (*use_memo( - |p| p.clone().map(|m| (*m).clone().map(Rc::new)), - prepared_value, - )) + (*use_memo(prepared_value, |p| { + p.clone().map(|m| (*m).clone().map(Rc::new)) + })) .clone() }; - let value = use_memo( - |v| match v.value { - Some(QuerySliceValue::Loading { .. }) | None => Err(Suspension::new()), - Some(QuerySliceValue::Completed { id, result: ref m }) => { - Ok((id, Rc::new(QueryState::Completed { result: m.clone() }))) - } - Some(QuerySliceValue::Outdated { id, result: ref m }) => Ok(( - id, - Rc::new(QueryState::Refreshing { - last_result: m.clone(), - }), - )), - }, - value_state.clone(), - ); + let value = use_memo(value_state.clone(), |v| match v.value { + Some(QuerySliceValue::Loading { .. }) | None => Err(Suspension::new()), + Some(QuerySliceValue::Completed { id, result: ref m }) => { + Ok((id, Rc::new(QueryState::Completed { result: m.clone() }))) + } + Some(QuerySliceValue::Outdated { id, result: ref m }) => Ok(( + id, + Rc::new(QueryState::Refreshing { + last_result: m.clone(), + }), + )), + }); { let input = input.clone(); let run_query = run_query.clone(); let dispatch_state = dispatch_state.clone(); - use_memo( - move |_| match prepared_value { - Some(m) => dispatch_state(QuerySliceAction::LoadPrepared { - id, - input, - result: m, - }), - None => run_query(RunQueryInput { - id, - input: input.clone(), - sender: Rc::default(), - is_refresh: false, - }), - }, - (), - ); + use_memo((), move |_| match prepared_value { + Some(m) => dispatch_state(QuerySliceAction::LoadPrepared { + id, + input, + result: m, + }), + None => run_query(RunQueryInput { + id, + input: input.clone(), + sender: Rc::default(), + is_refresh: false, + }), + }); } { let input = input.clone(); let run_query = run_query.clone(); - use_effect_with_deps( + use_effect_with( + (id, input, value_state.clone()), move |(id, input, value_state)| { if matches!(value_state.value, Some(QuerySliceValue::Outdated { .. })) { run_query(RunQueryInput { @@ -212,7 +207,6 @@ where || {} }, - (id, input, value_state.clone()), ); } diff --git a/crates/bounce/src/query/use_query.rs b/crates/bounce/src/query/use_query.rs index 128c6a2..ff28ead 100644 --- a/crates/bounce/src/query/use_query.rs +++ b/crates/bounce/src/query/use_query.rs @@ -212,49 +212,44 @@ pub fn use_query(input: Rc) -> SuspensionResult> where T: Query + 'static, { - let id = *use_memo(|_| Id::new(), ()); + let id = *use_memo((), |_| Id::new()); let value_state = use_input_selector_value::>(input.clone()); let dispatch_state = use_slice_dispatch::>(); let run_query = use_future_notion_runner::>(); - let value = use_memo( - |v| match v.value { - Some(QuerySliceValue::Loading { .. }) | None => Err(Suspension::new()), - Some(QuerySliceValue::Completed { id, result: ref m }) => { - Ok((id, Rc::new(QueryState::Completed { result: m.clone() }))) - } - Some(QuerySliceValue::Outdated { id, result: ref m }) => Ok(( - id, - Rc::new(QueryState::Refreshing { - last_result: m.clone(), - }), - )), - }, - value_state.clone(), - ); + let value = use_memo(value_state.clone(), |v| match v.value { + Some(QuerySliceValue::Loading { .. }) | None => Err(Suspension::new()), + Some(QuerySliceValue::Completed { id, result: ref m }) => { + Ok((id, Rc::new(QueryState::Completed { result: m.clone() }))) + } + Some(QuerySliceValue::Outdated { id, result: ref m }) => Ok(( + id, + Rc::new(QueryState::Refreshing { + last_result: m.clone(), + }), + )), + }); { let input = input.clone(); let run_query = run_query.clone(); - use_memo( - move |_| { - run_query(RunQueryInput { - id, - input: input.clone(), - sender: Rc::default(), - is_refresh: false, - }); - }, - (), - ); + use_memo((), move |_| { + run_query(RunQueryInput { + id, + input: input.clone(), + sender: Rc::default(), + is_refresh: false, + }); + }); } { let input = input.clone(); let run_query = run_query.clone(); - use_effect_with_deps( + use_effect_with( + (id, input, value_state.clone()), move |(id, input, value_state)| { if matches!(value_state.value, Some(QuerySliceValue::Outdated { .. })) { run_query(RunQueryInput { @@ -267,7 +262,6 @@ where || {} }, - (id, input, value_state.clone()), ); } diff --git a/crates/bounce/src/query/use_query_value.rs b/crates/bounce/src/query/use_query_value.rs index 7c41f35..dcf69cf 100644 --- a/crates/bounce/src/query/use_query_value.rs +++ b/crates/bounce/src/query/use_query_value.rs @@ -216,7 +216,7 @@ pub fn use_query_value(input: Rc) -> UseQueryValueHandle where T: Query + 'static, { - let id = *use_memo(|_| Id::new(), ()); + let id = *use_memo((), |_| Id::new()); let value = use_input_selector_value::>(input.clone()); let dispatch_state = use_slice_dispatch::>(); let run_query = use_future_notion_runner::>(); @@ -224,7 +224,8 @@ where { let input = input.clone(); let run_query = run_query.clone(); - use_effect_with_deps( + use_effect_with( + (id, input, value.value.clone()), move |(id, input, value)| { if value.is_none() || matches!(value, Some(QuerySliceValue::Outdated { .. })) { run_query(RunQueryInput { @@ -237,22 +238,18 @@ where || {} }, - (id, input, value.value.clone()), ); } - let state = use_memo( - |value| match value.value { - Some(QuerySliceValue::Completed { ref result, .. }) => QueryValueState::Completed { - result: result.clone(), - }, - Some(QuerySliceValue::Outdated { ref result, .. }) => QueryValueState::Refreshing { - last_result: result.clone(), - }, - Some(QuerySliceValue::Loading { .. }) | None => QueryValueState::Loading, + let state = use_memo(value, |value| match value.value { + Some(QuerySliceValue::Completed { ref result, .. }) => QueryValueState::Completed { + result: result.clone(), + }, + Some(QuerySliceValue::Outdated { ref result, .. }) => QueryValueState::Refreshing { + last_result: result.clone(), }, - value, - ); + Some(QuerySliceValue::Loading { .. }) | None => QueryValueState::Loading, + }); UseQueryValueHandle { input, diff --git a/crates/bounce/src/states/artifact.rs b/crates/bounce/src/states/artifact.rs index f06f22b..4c43c67 100644 --- a/crates/bounce/src/states/artifact.rs +++ b/crates/bounce/src/states/artifact.rs @@ -169,35 +169,26 @@ where { let artifact_dispatch = artifact_dispatch.clone(); - use_effect_with_deps( - move |(val, _)| { - artifact_dispatch(ArtifactAction::Insert(id, val.clone())); - || {} - }, - (props.value.clone(), root.clone()), - ); + use_effect_with((props.value.clone(), root.clone()), move |(val, _)| { + artifact_dispatch(ArtifactAction::Insert(id, val.clone())); + || {} + }); } #[allow(clippy::unused_unit)] { let _artifact_dispatch = artifact_dispatch.clone(); let _val = props.value.clone(); - let _ = use_prepared_state!( - move |_| -> () { - _artifact_dispatch(ArtifactAction::Insert(id, _val)); - }, - () - ); + let _ = use_prepared_state!((), move |_| -> () { + _artifact_dispatch(ArtifactAction::Insert(id, _val)); + }); } - use_effect_with_deps( - move |_| { - move || { - artifact_dispatch(ArtifactAction::Remove(id)); - } - }, - root, - ); + use_effect_with(root, move |_| { + move || { + artifact_dispatch(ArtifactAction::Remove(id)); + } + }); Html::default() } diff --git a/crates/bounce/src/states/input_selector.rs b/crates/bounce/src/states/input_selector.rs index ba5fce1..63ca456 100644 --- a/crates/bounce/src/states/input_selector.rs +++ b/crates/bounce/src/states/input_selector.rs @@ -276,22 +276,19 @@ where { let val = val.clone(); let root = root; - use_memo( - move |(root, input)| { - let state = root - .get_state::>() - .get_state(input.clone()); - - // we need to set the value here again in case the value has changed between the - // initial render and the listener is registered. - val.set(state.get(root.states())); - - state.listen(Rc::new(Callback::from(move |m| { - val.set(m); - }))) - }, - (root, input), - ); + use_memo((root, input), move |(root, input)| { + let state = root + .get_state::>() + .get_state(input.clone()); + + // we need to set the value here again in case the value has changed between the + // initial render and the listener is registered. + val.set(state.get(root.states())); + + state.listen(Rc::new(Callback::from(move |m| { + val.set(m); + }))) + }); } (*val).clone() } diff --git a/crates/bounce/src/states/slice.rs b/crates/bounce/src/states/slice.rs index 86dc82d..ced172a 100644 --- a/crates/bounce/src/states/slice.rs +++ b/crates/bounce/src/states/slice.rs @@ -280,20 +280,17 @@ where { let val = val.clone(); let root = root.clone(); - use_memo( - move |root| { - let state = root.get_state::>(); - - // we need to set the value here again in case the value has changed between the - // initial render and the listener is registered. - val.set(state.get()); - - state.listen(Rc::new(Callback::from(move |m| { - val.set(m); - }))) - }, - root, - ); + use_memo(root, move |root| { + let state = root.get_state::>(); + + // we need to set the value here again in case the value has changed between the + // initial render and the listener is registered. + val.set(state.get()); + + state.listen(Rc::new(Callback::from(move |m| { + val.set(m); + }))) + }); } let val = (*val).clone(); diff --git a/crates/bounce/tests/notion.rs b/crates/bounce/tests/notion.rs index f259790..f80eb4d 100644 --- a/crates/bounce/tests/notion.rs +++ b/crates/bounce/tests/notion.rs @@ -50,15 +50,12 @@ async fn test_notion_generic() { { let a = a.clone(); let b = b.clone(); - use_effect_with_deps( - move |_| { - a.set(State { inner: 1 }); - b.set(State { inner: 2 }); + use_effect_with((), move |_| { + a.set(State { inner: 1 }); + b.set(State { inner: 2 }); - || {} - }, - (), - ); + || {} + }); } html! { diff --git a/crates/bounce/tests/query.rs b/crates/bounce/tests/query.rs index 81e58c4..c7fab37 100755 --- a/crates/bounce/tests/query.rs +++ b/crates/bounce/tests/query.rs @@ -59,18 +59,15 @@ async fn test_query_requery_upon_state_change() { let my_query = use_query_value::(().into()); let set_my_state = use_atom_setter(); - use_effect_with_deps( - move |_| { - spawn_local(async move { - sleep(Duration::from_millis(50)).await; - - set_my_state(MyState { inner: 1 }); - }); - - || {} - }, - (), - ); + use_effect_with((), move |_| { + spawn_local(async move { + sleep(Duration::from_millis(50)).await; + + set_my_state(MyState { inner: 1 }); + }); + + || {} + }); match my_query.result() { None => { diff --git a/examples/title/src/main.rs b/examples/title/src/main.rs index f2f1a96..2a99cad 100644 --- a/examples/title/src/main.rs +++ b/examples/title/src/main.rs @@ -28,14 +28,11 @@ pub fn title_applier() -> Html { .map(|m| m.value.to_owned()) .unwrap_or_else(|| "unknown title".into()); - use_effect_with_deps( - |m| { - document().set_title(m); - - || {} - }, - title, - ); + use_effect_with(title, |m| { + document().set_title(m); + + || {} + }); Html::default() } From a6aaa5d0e393102690cb64c090a409e8f7cbad81 Mon Sep 17 00:00:00 2001 From: Marcel Date: Fri, 6 Oct 2023 19:18:41 +0200 Subject: [PATCH 3/4] Updated to make the collect functions compile --- crates/bounce/src/helmet/comp.rs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/crates/bounce/src/helmet/comp.rs b/crates/bounce/src/helmet/comp.rs index 1b8368f..460a8f9 100644 --- a/crates/bounce/src/helmet/comp.rs +++ b/crates/bounce/src/helmet/comp.rs @@ -42,7 +42,11 @@ fn collect_str_in_children(tag: &VNode) -> String { } fn collect_text_content(tag: &VTag) -> String { - collect_str_in_children(&tag.children().clone().into()) + if let Some(children) = tag.children() { + collect_str_in_children(children) + } else { + String::default() + } } fn collect_attributes(tag: &VTag) -> BTreeMap, Arc> { @@ -71,8 +75,11 @@ fn assert_empty_node(node: &VNode) { VNode::VRaw(_) => throw_str("expected nothing, found raw html."), } } + fn assert_empty_children(tag: &VTag) { - assert_empty_node(&tag.children().clone().into()) + if let Some(children) = tag.children() { + assert_empty_node(children); + } } #[derive(Properties, PartialEq, Clone)] From 2131407864feb4b8f9304251671af420bde373db Mon Sep 17 00:00:00 2001 From: Marcel Date: Sun, 8 Oct 2023 18:38:24 +0200 Subject: [PATCH 4/4] Updated CHANGELOG --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 041a3ba..6ce04a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,13 @@ +## Release 0.9.0 + +### Breaking Changes + +- Compatible with Yew 0.21. Due to the breaking API changes in Yew 0.21 not backwards compatible with Yew 0.20. + +### Other Changes + +- Updated the Gloo dependency to 0.10 + ## Release 0.8.0 ### Breaking Changes