From c42605c1adfdbdd7b519292fbfb42c64072a547c Mon Sep 17 00:00:00 2001 From: Maccesch Date: Sun, 4 Aug 2024 21:13:30 +0100 Subject: [PATCH] removed a bunch of warnings and test compile errors --- Cargo.toml | 8 ++++---- src/math/shared.rs | 4 ++-- src/storage/use_storage.rs | 2 +- src/sync_signal.rs | 8 ++++---- src/use_cycle_list.rs | 2 +- src/use_device_orientation.rs | 1 - src/use_display_media.rs | 2 +- src/use_infinite_scroll.rs | 4 ++-- src/use_intersection_observer.rs | 3 ++- src/use_interval_fn.rs | 4 ++-- src/use_mutation_observer.rs | 2 +- src/use_user_media.rs | 2 +- src/utils/signal_filtered.rs | 2 +- src/watch_with_options.rs | 18 ++++-------------- 14 files changed, 26 insertions(+), 36 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6da9423..22269ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,9 +26,9 @@ http1 = { version = "1", optional = true, package = "http" } http0_2 = { version = "0.2", optional = true, package = "http" } js-sys = "0.3" lazy_static = "1" -leptos = { version = "0.7.0-beta" } -leptos_axum = { version = "0.7.0-beta", optional = true } -leptos_actix = { version = "0.6", optional = true } +leptos = { version = "0.7.0-beta", git = "https://github.com/leptos-rs/leptos", branch = "leptos_0.7" } +leptos_axum = { version = "0.7.0-beta", optional = true, git = "https://github.com/leptos-rs/leptos", branch = "leptos_0.7" } +leptos_actix = { version = "0.7.0-beta", optional = true, git = "https://github.com/leptos-rs/leptos", branch = "leptos_0.7" } leptos-spin = { version = "0.2", optional = true } num = { version = "0.4", optional = true } paste = "1" @@ -131,7 +131,7 @@ features = [ [dev-dependencies] getrandom = { version = "0.2", features = ["js"] } -leptos_meta = "0.7.0-beta" +leptos_meta = { version = "0.7.0-beta", git = "https://github.com/leptos-rs/leptos", branch = "leptos_0.7" } rand = "0.8" codee = { version = "0.1", features = ["json_serde", "msgpack_serde", "base64", "prost"] } serde = { version = "1", features = ["derive"] } diff --git a/src/math/shared.rs b/src/math/shared.rs index 1b6e231..52d643b 100644 --- a/src/math/shared.rs +++ b/src/math/shared.rs @@ -9,7 +9,7 @@ macro_rules! use_partial_cmp { S: Into>, C: Send + Sync + 'static, for<'a> &'a C: IntoIterator, - N: PartialOrd + Clone + Send + Sync, + N: PartialOrd + Clone + Send + Sync + 'static, { let container = container.into(); @@ -48,7 +48,7 @@ macro_rules! use_simple_math { pub fn [](x: S) -> Signal where S: Into> + Send + Sync, - N: Float + Send + Sync, + N: Float + Send + Sync + 'static, { let x = x.into(); Signal::derive(move || x.get().$fn_name()) diff --git a/src/storage/use_storage.rs b/src/storage/use_storage.rs index fb80b93..a542494 100644 --- a/src/storage/use_storage.rs +++ b/src/storage/use_storage.rs @@ -6,7 +6,6 @@ use codee::{CodecError, Decoder, Encoder}; use default_struct_builder::DefaultBuilder; use leptos::prelude::wrappers::read::Signal; use leptos::prelude::*; -use send_wrapper::SendWrapper; use std::sync::Arc; use thiserror::Error; use wasm_bindgen::JsValue; @@ -199,6 +198,7 @@ where #[cfg(not(feature = "ssr"))] { use crate::{use_event_listener, use_window, watch_with_options, WatchOptions}; + use send_wrapper::SendWrapper; // Get storage API let storage = storage_type diff --git a/src/sync_signal.rs b/src/sync_signal.rs index 0887624..c22c0ee 100644 --- a/src/sync_signal.rs +++ b/src/sync_signal.rs @@ -177,7 +177,7 @@ where let mut stop_watch_right = None; if matches!(direction, SyncDirection::Both | SyncDirection::LeftToRight) { - stop_watch_left = Some(watch( + stop_watch_left = Some(Effect::watch( move || left.get(), move |new_value, _, _| { let new_value = (*transform_ltr)(new_value); @@ -191,7 +191,7 @@ where } if matches!(direction, SyncDirection::Both | SyncDirection::RightToLeft) { - stop_watch_right = Some(watch( + stop_watch_right = Some(Effect::watch( move || right.get(), move |new_value, _, _| { let new_value = (*transform_rtl)(new_value); @@ -206,10 +206,10 @@ where move || { if let Some(stop_watch_left) = &stop_watch_left { - stop_watch_left(); + stop_watch_left.stop(); } if let Some(stop_watch_right) = &stop_watch_right { - stop_watch_right(); + stop_watch_right.stop(); } } } diff --git a/src/use_cycle_list.rs b/src/use_cycle_list.rs index 5c1d3ce..d68eb56 100644 --- a/src/use_cycle_list.rs +++ b/src/use_cycle_list.rs @@ -155,7 +155,7 @@ where let _ = { let set = set.clone(); - watch(move || list.get(), move |_, _, _| set(index.get()), false) + Effect::watch(move || list.get(), move |_, _, _| set(index.get()), false) }; UseCycleListReturn { diff --git a/src/use_device_orientation.rs b/src/use_device_orientation.rs index 051a10d..f9c0f67 100644 --- a/src/use_device_orientation.rs +++ b/src/use_device_orientation.rs @@ -1,6 +1,5 @@ use cfg_if::cfg_if; use leptos::prelude::wrappers::read::Signal; -use send_wrapper::SendWrapper; /// Reactive [DeviceOrientationEvent](https://developer.mozilla.org/en-US/docs/Web/API/DeviceOrientationEvent). /// Provide web developers with information from the physical orientation of diff --git a/src/use_display_media.rs b/src/use_display_media.rs index 32db705..2ff5a2a 100644 --- a/src/use_display_media.rs +++ b/src/use_display_media.rs @@ -99,7 +99,7 @@ pub fn use_display_media_with_options( set_enabled.set(false); }; - let _ = watch( + Effect::watch( move || enabled.get(), move |enabled, _, _| { if *enabled { diff --git a/src/use_infinite_scroll.rs b/src/use_infinite_scroll.rs index e55642f..3723bbc 100644 --- a/src/use_infinite_scroll.rs +++ b/src/use_infinite_scroll.rs @@ -182,7 +182,7 @@ where } }))); - let _ = watch( + Effect::watch( move || is_element_visible.get(), move |visible, prev_visible, _| { if *visible && !prev_visible.copied().unwrap_or_default() { @@ -192,7 +192,7 @@ where true, ); - let _ = watch( + Effect::watch( move || state.arrived_state.get().get_direction(direction), move |arrived, prev_arrived, _| { if let Some(prev_arrived) = prev_arrived { diff --git a/src/use_intersection_observer.rs b/src/use_intersection_observer.rs index ef76eee..7a724b7 100644 --- a/src/use_intersection_observer.rs +++ b/src/use_intersection_observer.rs @@ -3,7 +3,6 @@ use cfg_if::cfg_if; use default_struct_builder::DefaultBuilder; use leptos::prelude::wrappers::read::Signal; use leptos::prelude::*; -use send_wrapper::SendWrapper; use std::marker::PhantomData; cfg_if! { if #[cfg(not(feature = "ssr"))] { @@ -101,6 +100,8 @@ where let cleanup = || {}; let stop = || {}; } else { + use send_wrapper::SendWrapper; + let closure_js = Closure::::new( move |entries: js_sys::Array, observer| { #[cfg(debug_assertions)] diff --git a/src/use_interval_fn.rs b/src/use_interval_fn.rs index e21fed4..a8432e8 100644 --- a/src/use_interval_fn.rs +++ b/src/use_interval_fn.rs @@ -129,7 +129,7 @@ where if matches!(interval, MaybeSignal::Dynamic(_)) { let resume = resume.clone(); - let stop_watch = watch( + let effect = Effect::watch( move || interval.get(), move |_, _, _| { if is_active.get() { @@ -138,7 +138,7 @@ where }, false, ); - on_cleanup(stop_watch); + on_cleanup(move || effect.stop()); } on_cleanup({ diff --git a/src/use_mutation_observer.rs b/src/use_mutation_observer.rs index 8f223c4..2333399 100644 --- a/src/use_mutation_observer.rs +++ b/src/use_mutation_observer.rs @@ -2,7 +2,6 @@ use crate::core::ElementsMaybeSignal; use cfg_if::cfg_if; use default_struct_builder::DefaultBuilder; use leptos::prelude::wrappers::read::Signal; -use send_wrapper::SendWrapper; use wasm_bindgen::prelude::*; cfg_if! { if #[cfg(not(feature = "ssr"))] { @@ -86,6 +85,7 @@ where #[cfg(not(feature = "ssr"))] { use crate::js; + use send_wrapper::SendWrapper; let closure_js = Closure::::new( move |entries: js_sys::Array, observer| { diff --git a/src/use_user_media.rs b/src/use_user_media.rs index 83ec073..64d2513 100644 --- a/src/use_user_media.rs +++ b/src/use_user_media.rs @@ -104,7 +104,7 @@ pub fn use_user_media_with_options( set_enabled.set(false); }; - let _ = watch( + Effect::watch( move || enabled.get(), move |enabled, _, _| { if *enabled { diff --git a/src/utils/signal_filtered.rs b/src/utils/signal_filtered.rs index 2763e9e..ad9ebe7 100644 --- a/src/utils/signal_filtered.rs +++ b/src/utils/signal_filtered.rs @@ -53,7 +53,7 @@ macro_rules! signal_filtered { options, ); - let _ = watch(move || value.get(), move |_, _, _| update(), false); + Effect::watch(move || value.get(), move |_, _, _| update(), false); filtered.into() } diff --git a/src/watch_with_options.rs b/src/watch_with_options.rs index 6c9c888..46cad32 100644 --- a/src/watch_with_options.rs +++ b/src/watch_with_options.rs @@ -129,7 +129,7 @@ where let filtered_callback = create_filter_wrapper(options.filter.filter_fn(), wrapped_callback.clone()); - leptos::prelude::watch( + let effect = Effect::watch( deps, move |deps_value, previous_deps_value, did_run_before| { cur_deps_value.replace(Some(deps_value.clone())); @@ -144,7 +144,9 @@ where prev_callback_value.replace(callback_value); }, options.immediate, - ) + ); + + move || effect.stop() // create_effect(move |did_run_before| { // if !is_active.get() { @@ -186,15 +188,3 @@ impl WatchOptions { filter ); } - -#[deprecated(since = "0.7.0", note = "Use `leptos::watch` instead")] -#[inline(always)] -pub fn watch(deps: DFn, callback: CFn) -> impl Fn() + Clone -where - DFn: Fn() -> W + 'static, - CFn: Fn(&W, Option<&W>, Option) -> T + Clone + 'static, - W: Clone + 'static, - T: Clone + 'static, -{ - leptos::prelude::watch(deps, callback, false) -}