diff --git a/src/core/elements_maybe_signal.rs b/src/core/elements_maybe_signal.rs index 9902280..069cd7b 100644 --- a/src/core/elements_maybe_signal.rs +++ b/src/core/elements_maybe_signal.rs @@ -4,8 +4,10 @@ use cfg_if::cfg_if; use leptos::html::{ElementType, HtmlElement}; use leptos::prelude::wrappers::read::Signal; use leptos::prelude::*; +use send_wrapper::SendWrapper; use std::marker::PhantomData; use std::ops::Deref; +use wasm_bindgen::JsCast; /// Used as an argument type to make it easily possible to pass either /// * a `web_sys` element that implements `E` (for example `EventTarget` or `Element`), @@ -58,9 +60,9 @@ impl With for ElementsMaybeSignal where T: Into + Clone + 'static, { - type Value = Vec>; + type Value = Vec>>; - fn with(&self, f: impl FnOnce(&Vec>) -> O) -> O { + fn with(&self, f: impl FnOnce(&Vec>>) -> O) -> O { match self { Self::Static(v) => f(v), Self::Dynamic(s) => s.with(f), @@ -68,7 +70,7 @@ where } } - fn try_with(&self, f: impl FnOnce(&Vec>) -> O) -> Option { + fn try_with(&self, f: impl FnOnce(&Vec>>) -> O) -> Option { match self { Self::Static(v) => Some(f(v)), Self::Dynamic(s) => s.try_with(f), @@ -81,9 +83,9 @@ impl WithUntracked for ElementsMaybeSignal where T: Into + Clone + 'static, { - type Value = Vec>; + type Value = Vec>>; - fn with_untracked(&self, f: impl FnOnce(&Vec>) -> O) -> O { + fn with_untracked(&self, f: impl FnOnce(&Vec>>) -> O) -> O { match self { Self::Static(t) => f(t), Self::Dynamic(s) => s.with_untracked(f), @@ -91,7 +93,10 @@ where } } - fn try_with_untracked(&self, f: impl FnOnce(&Vec>) -> O) -> Option { + fn try_with_untracked( + &self, + f: impl FnOnce(&Vec>>) -> O, + ) -> Option { match self { Self::Static(t) => Some(f(t)), Self::Dynamic(s) => s.try_with_untracked(f), @@ -107,7 +112,7 @@ where T: Into + Clone + 'static, { fn from(value: T) -> Self { - ElementsMaybeSignal::Static(vec![Some(value)]) + ElementsMaybeSignal::Static(vec![Some(SendWrapper::new(value))]) } } @@ -116,7 +121,7 @@ where T: Into + Clone + 'static, { fn from(target: Option) -> Self { - ElementsMaybeSignal::Static(vec![target]) + ElementsMaybeSignal::Static(vec![target.map(SendWrapper::new)]) } } @@ -127,7 +132,7 @@ macro_rules! impl_from_deref_option { E: From<$ty2> + 'static, { fn from(value: $ty) -> Self { - Self::Static(vec![(*value).clone()]) + Self::Static(vec![(*value).clone().map(SendWrapper::new)]) } } }; @@ -185,7 +190,7 @@ macro_rules! impl_from_signal_string { let mut list = Vec::with_capacity(node_list.length() as usize); for i in 0..node_list.length() { let node = node_list.get(i).expect("checked the range"); - list.push(Some(node)); + list.push(Some(SendWrapper::new(node))); } list } else { @@ -209,8 +214,8 @@ impl_from_signal_string!(Memo); impl_from_signal_string!(Signal<&str>); impl_from_signal_string!(ReadSignal<&str>); -impl_from_signal_string!(RwSignal<&str>); -impl_from_signal_string!(Memo<&str>); +impl_from_signal_string!(RwSignal<&'static str>); +impl_from_signal_string!(Memo<&'static str>); // From single signal /////////////////////////////////////////////////////////////// @@ -227,10 +232,10 @@ macro_rules! impl_from_signal_option { }; } -impl_from_signal_option!(Signal>); -impl_from_signal_option!(ReadSignal>); -impl_from_signal_option!(RwSignal>); -impl_from_signal_option!(Memo>); +impl_from_signal_option!(Signal>>); +impl_from_signal_option!(ReadSignal>>); +impl_from_signal_option!(RwSignal>>); +impl_from_signal_option!(Memo>>); macro_rules! impl_from_signal { ($ty:ty) => { @@ -245,10 +250,10 @@ macro_rules! impl_from_signal { }; } -impl_from_signal!(Signal); -impl_from_signal!(ReadSignal); -impl_from_signal!(RwSignal); -impl_from_signal!(Memo); +impl_from_signal!(Signal>); +impl_from_signal!(ReadSignal>); +impl_from_signal!(RwSignal>); +impl_from_signal!(Memo>); // From single NodeRef ////////////////////////////////////////////////////////////// @@ -257,13 +262,13 @@ macro_rules! impl_from_node_ref { impl From> for ElementsMaybeSignal<$ty, $ty> where R: ElementType + Clone + 'static, + R::Output: JsCast + Into<$ty> + Clone + 'static, { fn from(node_ref: NodeRef) -> Self { Self::Dynamic(Signal::derive(move || { vec![node_ref.get().map(move |el| { - let el = el.into_any(); - let el: $ty = el.deref().clone().into(); - el + let el: $ty = el.clone().into(); + SendWrapper::new(el) })] })) } @@ -276,23 +281,23 @@ impl_from_node_ref!(web_sys::Element); // From single leptos::html::HTMLElement /////////////////////////////////////////// -macro_rules! impl_from_html_element { - ($ty:ty) => { - impl From> for ElementsMaybeSignal<$ty, $ty> - where - E: ElementType, - E::Output: std::ops::Deref, - { - fn from(value: HtmlElement) -> Self { - let el: &$ty = value.deref(); - Self::Static(vec![Some(el.clone())]) - } - } - }; -} - -impl_from_html_element!(web_sys::EventTarget); -impl_from_html_element!(web_sys::Element); +// macro_rules! impl_from_html_element { +// ($ty:ty) => { +// impl From> for ElementsMaybeSignal<$ty, $ty> +// where +// E: ElementType, +// E::Output: std::ops::Deref, +// { +// fn from(value: HtmlElement) -> Self { +// let el: &$ty = value.deref(); +// Self::Static(vec![Some(el.clone())]) +// } +// } +// }; +// } +// +// impl_from_html_element!(web_sys::EventTarget); +// impl_from_html_element!(web_sys::Element); // From multiple static elements ////////////////////////////////////////////////////// @@ -301,7 +306,12 @@ where T: Into + Clone + 'static, { fn from(target: &[T]) -> Self { - Self::Static(target.iter().map(|t| Some(t.clone())).collect()) + Self::Static( + target + .iter() + .map(|t| Some(SendWrapper::new(t.clone()))) + .collect(), + ) } } @@ -310,7 +320,12 @@ where T: Into + Clone + 'static, { fn from(target: &[Option]) -> Self { - Self::Static(target.to_vec()) + Self::Static( + target + .iter() + .map(|t| t.clone().map(SendWrapper::new)) + .collect(), + ) } } @@ -319,7 +334,12 @@ where T: Into + Clone + 'static, { fn from(target: Vec) -> Self { - Self::Static(target.iter().map(|t| Some(t.clone())).collect()) + Self::Static( + target + .iter() + .map(|t| Some(SendWrapper::new(t.clone()))) + .collect(), + ) } } @@ -328,7 +348,12 @@ where T: Into + Clone + 'static, { fn from(target: Vec>) -> Self { - Self::Static(target.to_vec()) + Self::Static( + target + .into_iter() + .map(|t| t.map(SendWrapper::new)) + .collect(), + ) } } @@ -337,7 +362,12 @@ where T: Into + Clone + 'static, { fn from(target: [T; C]) -> Self { - Self::Static(target.iter().map(|t| Some(t.clone())).collect()) + Self::Static( + target + .into_iter() + .map(|t| Some(SendWrapper::new(t))) + .collect(), + ) } } @@ -346,7 +376,12 @@ where T: Into + Clone + 'static, { fn from(target: [Option; C]) -> Self { - Self::Static(target.to_vec()) + Self::Static( + target + .into_iter() + .map(|t| t.map(SendWrapper::new)) + .collect(), + ) } } @@ -357,7 +392,7 @@ macro_rules! impl_from_strings_inner { Self::Static( $target .iter() - .filter_map(|sel: &$str_ty| -> Option>> { + .filter_map(|sel: &$str_ty| -> Option>>> { cfg_if! { if #[cfg(feature = "ssr")] { let _ = sel; None @@ -368,7 +403,7 @@ macro_rules! impl_from_strings_inner { let mut list = Vec::with_capacity(node_list.length() as usize); for i in 0..node_list.length() { let node: $el_ty = node_list.get(i).expect("checked the range").unchecked_into(); - list.push(Some(node)); + list.push(Some(SendWrapper::new(node))); } Some(list) @@ -417,33 +452,33 @@ impl_from_strings!(web_sys::EventTarget, String); // From signal of vec //////////////////////////////////////////////////////////////// -impl From>> for ElementsMaybeSignal +impl From>>> for ElementsMaybeSignal where T: Into + Clone + 'static, { - fn from(signal: Signal>) -> Self { + fn from(signal: Signal>>) -> Self { Self::Dynamic(Signal::derive(move || { signal.get().into_iter().map(|t| Some(t)).collect() })) } } -impl From>>> for ElementsMaybeSignal +impl From>>>> for ElementsMaybeSignal where T: Into + Clone + 'static, { - fn from(target: Signal>>) -> Self { + fn from(target: Signal>>>) -> Self { Self::Dynamic(target) } } // From multiple signals ////////////////////////////////////////////////////////////// -impl From<&[Signal]> for ElementsMaybeSignal +impl From<&[Signal>]> for ElementsMaybeSignal where T: Into + Clone + 'static, { - fn from(list: &[Signal]) -> Self { + fn from(list: &[Signal>]) -> Self { let list = list.to_vec(); Self::Dynamic(Signal::derive(move || { @@ -452,11 +487,11 @@ where } } -impl From<&[Signal>]> for ElementsMaybeSignal +impl From<&[Signal>>]> for ElementsMaybeSignal where T: Into + Clone + 'static, { - fn from(list: &[Signal>]) -> Self { + fn from(list: &[Signal>>]) -> Self { let list = list.to_vec(); Self::Dynamic(Signal::derive(move || { @@ -465,11 +500,11 @@ where } } -impl From>> for ElementsMaybeSignal +impl From>>> for ElementsMaybeSignal where T: Into + Clone + 'static, { - fn from(list: Vec>) -> Self { + fn from(list: Vec>>) -> Self { let list = list.clone(); Self::Dynamic(Signal::derive(move || { @@ -478,11 +513,11 @@ where } } -impl From>>> for ElementsMaybeSignal +impl From>>>> for ElementsMaybeSignal where T: Into + Clone + 'static, { - fn from(list: Vec>>) -> Self { + fn from(list: Vec>>>) -> Self { let list = list.clone(); Self::Dynamic(Signal::derive(move || { @@ -491,11 +526,11 @@ where } } -impl From<[Signal; C]> for ElementsMaybeSignal +impl From<[Signal>; C]> for ElementsMaybeSignal where T: Into + Clone + 'static, { - fn from(list: [Signal; C]) -> Self { + fn from(list: [Signal>; C]) -> Self { let list = list.to_vec(); Self::Dynamic(Signal::derive(move || { @@ -504,11 +539,11 @@ where } } -impl From<[Signal>; C]> for ElementsMaybeSignal +impl From<[Signal>>; C]> for ElementsMaybeSignal where T: Into + Clone + 'static, { - fn from(list: [Signal>; C]) -> Self { + fn from(list: [Signal>>; C]) -> Self { let list = list.to_vec(); Self::Dynamic(Signal::derive(move || { @@ -526,9 +561,8 @@ macro_rules! impl_from_multi_node_ref_inner { .iter() .map(|node_ref| { node_ref.get().map(move |el| { - let el = el.into_any(); - let el: $ty = el.deref().clone().into(); - el + let el: $ty = el.clone().into(); + SendWrapper::new(el) }) }) .collect() @@ -541,6 +575,7 @@ macro_rules! impl_from_multi_node_ref { impl From<&[NodeRef]> for ElementsMaybeSignal<$ty, $ty> where R: ElementType + Clone + 'static, + R::Output: JsCast + Into<$ty> + Clone + 'static, { fn from(node_refs: &[NodeRef]) -> Self { let node_refs = node_refs.to_vec(); @@ -551,6 +586,7 @@ macro_rules! impl_from_multi_node_ref { impl From<[NodeRef; C]> for ElementsMaybeSignal<$ty, $ty> where R: ElementType + Clone + 'static, + R::Output: JsCast + Into<$ty> + Clone + 'static, { fn from(node_refs: [NodeRef; C]) -> Self { let node_refs = node_refs.to_vec(); @@ -561,6 +597,7 @@ macro_rules! impl_from_multi_node_ref { impl From>> for ElementsMaybeSignal<$ty, $ty> where R: ElementType + Clone + 'static, + R::Output: JsCast + Into<$ty> + Clone + 'static, { fn from(node_refs: Vec>) -> Self { let node_refs = node_refs.clone(); diff --git a/src/core/maybe_rw_signal.rs b/src/core/maybe_rw_signal.rs index cc7cbd0..3ac2b67 100644 --- a/src/core/maybe_rw_signal.rs +++ b/src/core/maybe_rw_signal.rs @@ -50,26 +50,38 @@ impl From> for MaybeRwSignal { } } -impl From> for MaybeRwSignal { +impl From> for MaybeRwSignal +where + T: Send + Sync, +{ fn from(s: ReadSignal) -> Self { Self::DynamicRead(s.into()) } } -impl From> for MaybeRwSignal { +impl From> for MaybeRwSignal +where + T: Send + Sync, +{ fn from(s: Memo) -> Self { Self::DynamicRead(s.into()) } } -impl From> for MaybeRwSignal { +impl From> for MaybeRwSignal +where + T: Send + Sync, +{ fn from(s: RwSignal) -> Self { let (r, w) = s.split(); Self::DynamicRw(r.into(), w) } } -impl From<(ReadSignal, WriteSignal)> for MaybeRwSignal { +impl From<(ReadSignal, WriteSignal)> for MaybeRwSignal +where + T: Send + Sync, +{ fn from(s: (ReadSignal, WriteSignal)) -> Self { Self::DynamicRw(s.0.into(), s.1) } @@ -87,7 +99,10 @@ impl From<&str> for MaybeRwSignal { } } -impl MaybeRwSignal { +impl MaybeRwSignal +where + T: Send + Sync, +{ pub fn into_signal(self) -> (Signal, WriteSignal) { match self { Self::DynamicRead(s) => { diff --git a/src/core/use_rw_signal.rs b/src/core/use_rw_signal.rs index a57ec23..73a7e85 100644 --- a/src/core/use_rw_signal.rs +++ b/src/core/use_rw_signal.rs @@ -22,7 +22,7 @@ where impl Default for UseRwSignal where - T: Default, + T: Default + Send + Sync, { fn default() -> Self { Self::Combined(Default::default()) @@ -47,7 +47,10 @@ impl DefinedAt for UseRwSignal { } } -impl With for UseRwSignal { +impl With for UseRwSignal +where + T: Send + Sync, +{ type Value = T; fn with(&self, f: impl FnOnce(&T) -> R) -> R { @@ -65,7 +68,10 @@ impl With for UseRwSignal { } } -impl WithUntracked for UseRwSignal { +impl WithUntracked for UseRwSignal +where + T: Send + Sync, +{ type Value = T; fn with_untracked(&self, f: impl FnOnce(&T) -> R) -> R { diff --git a/src/lib.rs b/src/lib.rs index 41112af..aaf827c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,11 +25,11 @@ mod is_none; mod is_ok; mod is_some; mod on_click_outside; -mod use_user_media; mod signal_debounced; mod signal_throttled; mod sync_signal; -mod use_active_element; +mod use_user_media; +// mod use_active_element; mod use_breakpoints; mod use_broadcast_channel; mod use_color_mode; @@ -91,11 +91,11 @@ pub use is_none::*; pub use is_ok::*; pub use is_some::*; pub use on_click_outside::*; -pub use use_user_media::*; pub use signal_debounced::*; pub use signal_throttled::*; pub use sync_signal::*; -pub use use_active_element::*; +pub use use_user_media::*; +// pub use use_active_element::*; pub use use_breakpoints::*; pub use use_broadcast_channel::*; pub use use_color_mode::*; diff --git a/src/math/shared.rs b/src/math/shared.rs index 3d96dcd..1b6e231 100644 --- a/src/math/shared.rs +++ b/src/math/shared.rs @@ -7,9 +7,9 @@ macro_rules! use_partial_cmp { pub fn $fn_name(container: S) -> Signal> where S: Into>, - C: 'static, + C: Send + Sync + 'static, for<'a> &'a C: IntoIterator, - N: PartialOrd + Clone, + N: PartialOrd + Clone + Send + Sync, { let container = container.into(); @@ -47,8 +47,8 @@ macro_rules! use_simple_math { $(#[$outer])* pub fn [](x: S) -> Signal where - S: Into>, - N: Float, + S: Into> + Send + Sync, + N: Float + Send + Sync, { let x = x.into(); Signal::derive(move || x.get().$fn_name()) diff --git a/src/sync_signal.rs b/src/sync_signal.rs index 0595ffe..0887624 100644 --- a/src/sync_signal.rs +++ b/src/sync_signal.rs @@ -148,7 +148,7 @@ pub fn sync_signal( right: impl Into>, ) -> impl Fn() + Clone where - T: Clone + PartialEq + 'static, + T: Clone + PartialEq + Send + Sync + 'static, { sync_signal_with_options(left, right, SyncSignalOptions::default()) } @@ -160,8 +160,8 @@ pub fn sync_signal_with_options( options: SyncSignalOptions, ) -> impl Fn() + Clone where - L: Clone + PartialEq + 'static, - R: Clone + PartialEq + 'static, + L: Clone + PartialEq + Send + Sync + 'static, + R: Clone + PartialEq + Send + Sync + 'static, { let SyncSignalOptions { immediate, diff --git a/src/use_breakpoints.rs b/src/use_breakpoints.rs index 33016ca..fee58fe 100644 --- a/src/use_breakpoints.rs +++ b/src/use_breakpoints.rs @@ -110,7 +110,7 @@ use std::hash::Hash; /// /// Since internally this uses [`use_media_query`], which returns always `false` on the server, /// the returned methods also will return `false`. -pub fn use_breakpoints( +pub fn use_breakpoints( breakpoints: HashMap, ) -> UseBreakpointsReturn { UseBreakpointsReturn { breakpoints } @@ -118,7 +118,7 @@ pub fn use_breakpoints( /// Return type of [`use_breakpoints`] #[derive(Clone)] -pub struct UseBreakpointsReturn { +pub struct UseBreakpointsReturn { breakpoints: HashMap, } @@ -184,7 +184,7 @@ macro_rules! impl_cmp_reactively { }; } -impl UseBreakpointsReturn { +impl UseBreakpointsReturn { fn match_(query: &str) -> bool { if let Ok(Some(query_list)) = use_window().match_media(query) { return query_list.matches(); diff --git a/src/use_broadcast_channel.rs b/src/use_broadcast_channel.rs index 22fe06d..9abd612 100644 --- a/src/use_broadcast_channel.rs +++ b/src/use_broadcast_channel.rs @@ -4,6 +4,7 @@ use crate::{ use codee::{CodecError, Decoder, Encoder}; use leptos::ev::messageerror; use leptos::prelude::*; +use send_wrapper::SendWrapper; use thiserror::Error; use wasm_bindgen::JsValue; @@ -80,12 +81,15 @@ pub fn use_broadcast_channel( >::Error, > where + T: Send + Sync, C: Encoder + Decoder, + >::Error: Send + Sync, + >::Error: Send + Sync, { let is_supported = use_supported(|| js!("BroadcastChannel" in &window())); let (is_closed, set_closed) = signal(false); - let (channel, set_channel) = signal(None::); + let (channel, set_channel) = signal(None::>); let (message, set_message) = signal(None::); let (error, set_error) = signal( None::>::Error, >::Error>>, @@ -99,7 +103,9 @@ where channel .post_message(&msg.into()) .map_err(|err| { - set_error.set(Some(UseBroadcastChannelError::PostMessage(err))) + set_error.set(Some(UseBroadcastChannelError::PostMessage( + SendWrapper::new(err), + ))) }) .ok(); } @@ -124,7 +130,7 @@ where if is_supported.get_untracked() { let channel_val = web_sys::BroadcastChannel::new(name).ok(); - set_channel.set(channel_val.clone()); + set_channel.set(channel_val.clone().map(SendWrapper::new)); if let Some(channel) = channel_val { let _ = use_event_listener_with_options( @@ -151,7 +157,9 @@ where channel.clone(), messageerror, move |event| { - set_error.set(Some(UseBroadcastChannelError::MessageEvent(event))); + set_error.set(Some(UseBroadcastChannelError::MessageEvent( + SendWrapper::new(event), + ))); }, UseEventListenerOptions::default().passive(true), ); @@ -188,7 +196,7 @@ where pub is_supported: Signal, /// The broadcast channel that is wrapped by this function - pub channel: Signal>, + pub channel: Signal>>, /// Latest message received from the channel pub message: Signal>, @@ -209,9 +217,9 @@ where #[derive(Debug, Error)] pub enum UseBroadcastChannelError { #[error("failed to post message")] - PostMessage(JsValue), + PostMessage(SendWrapper), #[error("channel message error")] - MessageEvent(web_sys::MessageEvent), + MessageEvent(SendWrapper), #[error("failed to (de)encode value")] Codec(CodecError), #[error("received value is not a string")] diff --git a/src/use_device_orientation.rs b/src/use_device_orientation.rs index d7b1265..d2db892 100644 --- a/src/use_device_orientation.rs +++ b/src/use_device_orientation.rs @@ -36,10 +36,10 @@ use leptos::prelude::wrappers::read::Signal; pub fn use_device_orientation() -> UseDeviceOrientationReturn { cfg_if! { if #[cfg(feature = "ssr")] { let is_supported = Signal::derive(|| false); - let absolute = || false; - let alpha = || None; - let beta = || None; - let gamma = || None; + let absolute = Signal::derive(|| false); + let alpha = Signal::derive(|| None); + let beta = Signal::derive(|| None); + let gamma = Signal::derive(|| None); } else { use leptos::prelude::*; use crate::{use_event_listener_with_options, UseEventListenerOptions, use_supported, js}; diff --git a/src/use_draggable.rs b/src/use_draggable.rs index 796ba51..43f4893 100644 --- a/src/use_draggable.rs +++ b/src/use_draggable.rs @@ -5,8 +5,9 @@ use leptos::ev::{pointerdown, pointermove, pointerup}; use leptos::prelude::diagnostics::SpecialNonReactiveZone; use leptos::prelude::wrappers::read::Signal; use leptos::prelude::*; +use send_wrapper::SendWrapper; use std::marker::PhantomData; -use std::rc::Rc; +use std::sync::Arc; use wasm_bindgen::JsCast; use web_sys::PointerEvent; @@ -92,11 +93,12 @@ where let target = target.into(); let dragging_handle = if let Some(handle) = handle { - let handle = (handle).into(); - Signal::derive(move || handle.get().map(|handle| handle.into())) + // let handle = Signal::derive(|| SendWrapper::new(handle)); + let handle: ElementMaybeSignal<_, _> = handle.into(); + Signal::derive(move || handle.get().map(|handle| SendWrapper::new(handle.into()))) } else { let target = target.clone(); - Signal::derive(move || target.get().map(|target| target.into())) + Signal::derive(move || target.get().map(|target| SendWrapper::new(target.into()))) }; let (position, set_position) = initial_value.into_signal(); @@ -280,13 +282,13 @@ where initial_value: MaybeRwSignal, /// Callback when the dragging starts. Return `false` to prevent dragging. - on_start: Rc bool>, + on_start: Arc bool + Send + Sync>, /// Callback during dragging. - on_move: Rc, + on_move: Arc, /// Callback when dragging end. - on_end: Rc, + on_end: Arc, #[builder(skip)] _marker1: PhantomData, @@ -306,9 +308,9 @@ impl Default handle: None, pointer_types: vec![PointerType::Mouse, PointerType::Touch, PointerType::Pen], initial_value: MaybeRwSignal::default(), - on_start: Rc::new(|_| true), - on_move: Rc::new(|_| {}), - on_end: Rc::new(|_| {}), + on_start: Arc::new(|_| true), + on_move: Arc::new(|_| {}), + on_end: Arc::new(|_| {}), _marker1: PhantomData, _marker2: PhantomData, } diff --git a/src/use_drop_zone.rs b/src/use_drop_zone.rs index 6756866..f10a88d 100644 --- a/src/use_drop_zone.rs +++ b/src/use_drop_zone.rs @@ -3,8 +3,9 @@ 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::fmt::{Debug, Formatter}; -use std::rc::Rc; +use std::sync::Arc; cfg_if! { if #[cfg(not(feature = "ssr"))] { use crate::use_event_listener; @@ -73,7 +74,7 @@ where T: Into + Clone + 'static, { let (is_over_drop_zone, set_over_drop_zone) = signal(false); - let (files, set_files) = signal(Vec::::new()); + let (files, set_files) = signal(Vec::>::new()); #[cfg(not(feature = "ssr"))] { @@ -176,22 +177,22 @@ where #[cfg_attr(feature = "ssr", allow(dead_code))] pub struct UseDropZoneOptions { /// Event handler for the [`drop`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/drop_event) event - on_drop: Rc, + on_drop: Arc, /// Event handler for the [`dragenter`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dragenter_event) event - on_enter: Rc, + on_enter: Arc, /// Event handler for the [`dragleave`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dragleave_event) event - on_leave: Rc, + on_leave: Arc, /// Event handler for the [`dragover`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dragover_event) event - on_over: Rc, + on_over: Arc, } impl Default for UseDropZoneOptions { fn default() -> Self { Self { - on_drop: Rc::new(|_| {}), - on_enter: Rc::new(|_| {}), - on_leave: Rc::new(|_| {}), - on_over: Rc::new(|_| {}), + on_drop: Arc::new(|_| {}), + on_enter: Arc::new(|_| {}), + on_leave: Arc::new(|_| {}), + on_over: Arc::new(|_| {}), } } } @@ -214,7 +215,7 @@ pub struct UseDropZoneEvent { /// Return type of [`use_drop_zone`]. pub struct UseDropZoneReturn { /// Files being handled - pub files: Signal>, + pub files: Signal>>, /// Whether the files (dragged by the pointer) are over the drop zone pub is_over_drop_zone: Signal, } diff --git a/src/use_event_source.rs b/src/use_event_source.rs index dddf76b..e857a10 100644 --- a/src/use_event_source.rs +++ b/src/use_event_source.rs @@ -259,9 +259,9 @@ where for event_name in named_events.clone() { let _ = use_event_listener( es.clone(), - leptos::ev::Custom::::new(event_name), + leptos::ev::Custom::::new(event_name), move |e| { - set_event.set(Some(e.clone())); + set_event.set(Some(SendWrapper::new(e.clone()))); let data_string = js!(e["data"]).ok().and_then(|d| d.as_string()); set_data_from_string(data_string); }, diff --git a/src/use_websocket.rs b/src/use_websocket.rs index 51b657f..2cf593f 100644 --- a/src/use_websocket.rs +++ b/src/use_websocket.rs @@ -303,9 +303,11 @@ where Some(Arc::new(move || { if !manually_closed_ref.get_value() && !reconnect_limit.is_exceeded_by(reconnect_times_ref.get_value()) - && ws_ref.get_value().map_or(false, |ws: SendWrapper| { - ws.ready_state() != WebSocket::OPEN - }) + && ws_ref + .get_value() + .map_or(false, |ws: SendWrapper| { + ws.ready_state() != WebSocket::OPEN + }) { reconnect_timer_ref.set_value( set_timeout_with_handle( @@ -417,7 +419,7 @@ where on_message(&val); #[cfg(debug_assertions)] - drop(zone); + drop(zone); set_message.set(Some(val)); } @@ -628,7 +630,7 @@ impl ReconnectLimit { } } -type ArcFnBytes = Arc; +type ArcFnBytes = Arc; /// Options for [`use_websocket_with_options`]. #[derive(DefaultBuilder)] @@ -644,7 +646,7 @@ where /// `WebSocket` message callback for text. on_message_raw: Arc, /// `WebSocket` message callback for binary. - on_message_raw_bytes: ArcFnBytes + Send + Sync, + on_message_raw_bytes: ArcFnBytes, /// `WebSocket` error callback. #[builder(skip)] on_error: Arc) + Send + Sync>, diff --git a/src/utils/signal_filtered.rs b/src/utils/signal_filtered.rs index f397e5e..2763e9e 100644 --- a/src/utils/signal_filtered.rs +++ b/src/utils/signal_filtered.rs @@ -15,7 +15,7 @@ macro_rules! signal_filtered { ) -> Signal where S: Into>, - T: Clone + 'static, + T: Clone + Send + Sync + 'static, { [](value, ms, [<$filter_name:camel Options>]::default()) } @@ -36,7 +36,7 @@ macro_rules! signal_filtered { ) -> Signal where S: Into>, - T: Clone + 'static, + T: Clone + Send + Sync + 'static, { let value = value.into(); let ms = ms.into();