diff --git a/src/select/mod.rs b/src/select/mod.rs index 53477cf..8778e5c 100644 --- a/src/select/mod.rs +++ b/src/select/mod.rs @@ -1,9 +1,4 @@ -use crate::{ - teleport::Teleport, - theme::use_theme, - utils::{dom::window_event_listener, mount_style::mount_style}, - Theme, -}; +use crate::{teleport::Teleport, theme::use_theme, utils::mount_style::mount_style, Theme}; use leptos::*; use std::hash::Hash; use stylers::style_sheet_str; @@ -73,7 +68,7 @@ where } is_show_popover.set(false); }); - on_cleanup(timer); + on_cleanup(move || timer.remove()); let temp_options = options.clone(); let select_option_label = create_memo(move |_| match value.get() { diff --git a/src/slider/mod.rs b/src/slider/mod.rs index 783385b..1daa6c6 100644 --- a/src/slider/mod.rs +++ b/src/slider/mod.rs @@ -1,8 +1,4 @@ -use crate::{ - theme::use_theme, - utils::{dom::window_event_listener, mount_style::mount_style}, - Theme, -}; +use crate::{theme::use_theme, utils::mount_style::mount_style, Theme}; use leptos::*; use stylers::style_sheet_str; use wasm_bindgen::JsCast; @@ -47,7 +43,7 @@ pub fn Slider( let on_mouse_up = window_event_listener(ev::mouseup, move |_| { set_mouse_move.set(false); }); - on_cleanup(on_mouse_up); + on_cleanup(move || on_mouse_up.remove()); let on_mouse_move = window_event_listener(ev::mousemove, move |ev| { if is_mouse_move.get_untracked() { @@ -68,7 +64,7 @@ pub fn Slider( }; } }); - on_cleanup(on_mouse_move); + on_cleanup(move || on_mouse_move.remove()); view! { class=class_name,
diff --git a/src/utils/dom.rs b/src/utils/dom.rs deleted file mode 100644 index 22cd95b..0000000 --- a/src/utils/dom.rs +++ /dev/null @@ -1,28 +0,0 @@ -use leptos::window; -use leptos_dom::ev; -use std::borrow::Cow; -use wasm_bindgen::{prelude::Closure, JsCast}; - -pub fn window_event_listener( - event: E, - cb: impl Fn(E::EventType) + 'static, -) -> impl FnOnce() -> () -where - E::EventType: JsCast, -{ - fn wel( - cb: Box, - event_name: Cow<'static, str>, - ) -> impl FnOnce() -> () + 'static { - let cb = Closure::wrap(cb).into_js_value(); - _ = window().add_event_listener_with_callback(&event_name, cb.unchecked_ref()); - move || { - _ = window().remove_event_listener_with_callback(&event_name, cb.unchecked_ref()); - } - } - - wel( - Box::new(move |e| cb(e.unchecked_into::())), - event.name(), - ) -} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 6a1aceb..f8a5cd4 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,2 +1 @@ -pub mod dom; pub(crate) mod mount_style;