diff --git a/examples/axum_js_ssr/src/app.rs b/examples/axum_js_ssr/src/app.rs index b4cbded87e..c7681f2e78 100644 --- a/examples/axum_js_ssr/src/app.rs +++ b/examples/axum_js_ssr/src/app.rs @@ -674,7 +674,7 @@ fn CodeDemoWasm(mode: WasmDemo) -> impl IntoView { leptos::logging::log!("wasm csr_listener listener added"); // Dispatch the event when this view is finally mounted onto the DOM. - request_animation_frame(move || { + _ = request_animation_frame(move || { let event = web_sys::Event::new("hljs_hook") .expect("error creating hljs_hook event"); document.dispatch_event(&event) @@ -693,7 +693,7 @@ fn CodeDemoWasm(mode: WasmDemo) -> impl IntoView { "Loading code example..."

}>{ move || Suspend::new(async move { Effect::new(move |_| { - request_animation_frame(move || { + _ = request_animation_frame(move || { leptos::logging::log!("request_animation_frame invoking hljs::highlight_all"); // under SSR this is an noop, but it wouldn't be called under there anyway because // it isn't the isomorphic version, i.e. Effect::new_isomorphic(...). @@ -819,7 +819,7 @@ fn WasmBindgenJSHookReadyEvent() -> impl IntoView { leptos::logging::log!("wasm csr_listener listener added"); // Dispatch the event when this view is finally mounted onto the DOM. - request_animation_frame(move || { + _ = request_animation_frame(move || { let event = web_sys::Event::new("hljs_hook") .expect("error creating hljs_hook event"); document.dispatch_event(&event) @@ -870,7 +870,7 @@ fn WasmBindgenEffect() -> impl IntoView { let example = r#""Loading code example..."

}>{ move || Suspend::new(async move { Effect::new(move |_| { - request_animation_frame(move || { + _ = request_animation_frame(move || { leptos::logging::log!("request_animation_frame invoking hljs::highlight_all"); // under SSR this is an noop. crate::hljs::highlight_all(); diff --git a/examples/router/src/api.rs b/examples/router/src/api.rs index 0d602361e2..f4ba62fc08 100644 --- a/examples/router/src/api.rs +++ b/examples/router/src/api.rs @@ -97,7 +97,7 @@ fn delay( duration: Duration, ) -> impl Future> + Send { let (tx, rx) = oneshot::channel(); - set_timeout( + _ = set_timeout( move || { _ = tx.send(()); }, diff --git a/examples/timer/src/lib.rs b/examples/timer/src/lib.rs index c04241940c..34ae221aaa 100644 --- a/examples/timer/src/lib.rs +++ b/examples/timer/src/lib.rs @@ -50,7 +50,7 @@ where }; // here, we return the handle - set_interval_with_handle( + set_interval( f.clone(), // this is the only reactive access, so this effect will only // re-run when the interval changes diff --git a/leptos/src/animated_show.rs b/leptos/src/animated_show.rs index 5d8feff7d5..e0e59ca0d0 100644 --- a/leptos/src/animated_show.rs +++ b/leptos/src/animated_show.rs @@ -83,7 +83,7 @@ pub fn AnimatedShow( } else { cls.set(hide_class); - let h = leptos_dom::helpers::set_timeout_with_handle( + let h = leptos_dom::helpers::set_timeout( move || show.set(false), hide_delay, ) diff --git a/leptos_dom/examples/test-bench/src/main.rs b/leptos_dom/examples/test-bench/src/main.rs index 0df8c42c85..b2dbb9611d 100644 --- a/leptos_dom/examples/test-bench/src/main.rs +++ b/leptos_dom/examples/test-bench/src/main.rs @@ -73,14 +73,14 @@ where let to = to.into_iter().collect::>(); let (list, set_list) = create_signal(from.clone()); - request_animation_frame({ + _ = request_animation_frame({ let to = to.clone(); let then = then.clone(); move || { set_list(to); if let Some(then) = then { - request_animation_frame({ + _ = request_animation_frame({ move || { set_list(then); } diff --git a/leptos_dom/src/helpers.rs b/leptos_dom/src/helpers.rs index 9d878bd7d3..86c9e18b9f 100644 --- a/leptos_dom/src/helpers.rs +++ b/leptos_dom/src/helpers.rs @@ -116,7 +116,7 @@ pub fn event_target_checked(ev: &web_sys::Event) -> bool { .checked() } -/// Handle that is generated by [request_animation_frame_with_handle] and can +/// Handle that is generated by [request_animation_frame] and can /// be used to cancel the animation frame request. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct AnimationFrameRequestHandle(i32); @@ -129,18 +129,6 @@ impl AnimationFrameRequestHandle { } } -/// Runs the given function between the next repaint using -/// [`Window.requestAnimationFrame`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame). -/// -/// ### Note about Context -/// -/// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with). -#[cfg_attr(feature = "tracing", instrument(level = "trace", skip_all))] -#[inline(always)] -pub fn request_animation_frame(cb: impl FnOnce() + 'static) { - _ = request_animation_frame_with_handle(cb); -} - // Closure::once_into_js only frees the callback when it's actually // called, so this instead uses into_js_value, which can be freed by // the host JS engine's GC if it supports weak references (which all @@ -169,7 +157,7 @@ fn closure_once(cb: impl FnOnce() + 'static) -> JsValue { /// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with). #[cfg_attr(feature = "tracing", instrument(level = "trace", skip_all))] #[inline(always)] -pub fn request_animation_frame_with_handle( +pub fn request_animation_frame( cb: impl FnOnce() + 'static, ) -> Result { #[cfg(feature = "tracing")] @@ -190,7 +178,7 @@ pub fn request_animation_frame_with_handle( raf(closure_once(cb)) } -/// Handle that is generated by [request_idle_callback_with_handle] and can be +/// Handle that is generated by [request_idle_callback] and can be /// used to cancel the idle callback. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct IdleCallbackHandle(u32); @@ -203,18 +191,6 @@ impl IdleCallbackHandle { } } -/// Queues the given function during an idle period using -/// [`Window.requestIdleCallback`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestIdleCallback). -/// -/// ### Note about Context -/// -/// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with). -#[cfg_attr(feature = "tracing", instrument(level = "trace", skip_all))] -#[inline(always)] -pub fn request_idle_callback(cb: impl Fn() + 'static) { - _ = request_idle_callback_with_handle(cb); -} - /// Queues the given function during an idle period using /// [`Window.requestIdleCallback`](https://developer.mozilla.org/en-US/docs/Web/API/window/requestIdleCallback), /// returning a cancelable handle. @@ -224,7 +200,7 @@ pub fn request_idle_callback(cb: impl Fn() + 'static) { /// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with). #[cfg_attr(feature = "tracing", instrument(level = "trace", skip_all))] #[inline(always)] -pub fn request_idle_callback_with_handle( +pub fn request_idle_callback( cb: impl Fn() + 'static, ) -> Result { #[cfg(feature = "tracing")] @@ -261,7 +237,7 @@ pub fn queue_microtask(task: impl FnOnce() + 'static) { tachys::renderer::dom::queue_microtask(task); } -/// Handle that is generated by [set_timeout_with_handle] and can be used to clear the timeout. +/// Handle that is generated by [set_timeout] and can be used to clear the timeout. #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub struct TimeoutHandle(i32); @@ -273,20 +249,6 @@ impl TimeoutHandle { } } -/// Executes the given function after the given duration of time has passed. -/// [`setTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout). -/// -/// ### Note about Context -/// -/// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with). -#[cfg_attr( - feature = "tracing", - instrument(level = "trace", skip_all, fields(duration = ?duration)) -)] -pub fn set_timeout(cb: impl FnOnce() + 'static, duration: Duration) { - _ = set_timeout_with_handle(cb, duration); -} - /// Executes the given function after the given duration of time has passed, returning a cancelable handle. /// [`setTimeout()`](https://developer.mozilla.org/en-US/docs/Web/API/setTimeout). /// @@ -298,7 +260,7 @@ pub fn set_timeout(cb: impl FnOnce() + 'static, duration: Duration) { instrument(level = "trace", skip_all, fields(duration = ?duration)) )] #[inline(always)] -pub fn set_timeout_with_handle( +pub fn set_timeout( cb: impl FnOnce() + 'static, duration: Duration, ) -> Result { @@ -391,7 +353,7 @@ pub fn debounce( if let Some(timer) = timer.write().unwrap().take() { timer.clear(); } - let handle = set_timeout_with_handle( + let handle = set_timeout( { let cb = Arc::clone(&cb); move || { @@ -418,20 +380,6 @@ impl IntervalHandle { } } -/// Repeatedly calls the given function, with a delay of the given duration between calls. -/// See [`setInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/setInterval). -/// -/// ### Note about Context -/// -/// The callback is called outside of the reactive ownership tree. This means that it does not have access to context via [`use_context`](reactive_graph::owner::use_context). If you want to use context inside the callback, you should either call `use_context` in the body of the component, and move the value into the callback, or access the current owner inside the component body using [`Owner::current`](reactive_graph::owner::Owner::current) and reestablish it in the callback with [`Owner::with`](reactive_graph::owner::Owner::with). -#[cfg_attr( - feature = "tracing", - instrument(level = "trace", skip_all, fields(duration = ?duration)) -)] -pub fn set_interval(cb: impl Fn() + 'static, duration: Duration) { - _ = set_interval_with_handle(cb, duration); -} - /// Repeatedly calls the given function, with a delay of the given duration between calls, /// returning a cancelable handle. /// See [`setInterval()`](https://developer.mozilla.org/en-US/docs/Web/API/setInterval). @@ -444,7 +392,7 @@ pub fn set_interval(cb: impl Fn() + 'static, duration: Duration) { instrument(level = "trace", skip_all, fields(duration = ?duration)) )] #[inline(always)] -pub fn set_interval_with_handle( +pub fn set_interval( cb: impl Fn() + 'static, duration: Duration, ) -> Result { diff --git a/projects/bevy3d_ui/src/routes/demo1.rs b/projects/bevy3d_ui/src/routes/demo1.rs index 23e0a591f0..8e5a602e2f 100644 --- a/projects/bevy3d_ui/src/routes/demo1.rs +++ b/projects/bevy3d_ui/src/routes/demo1.rs @@ -20,7 +20,7 @@ pub fn Demo1() -> impl IntoView { // We need to add the 3D view onto the canvas post render. Effect::new(move |_| { - request_animation_frame(move || { + _ = request_animation_frame(move || { scene_sig.get_untracked().setup(); }); }); diff --git a/projects/sso_auth_axum/src/lib.rs b/projects/sso_auth_axum/src/lib.rs index d5fc9ce4a8..3d7760c264 100644 --- a/projects/sso_auth_axum/src/lib.rs +++ b/projects/sso_auth_axum/src/lib.rs @@ -95,7 +95,7 @@ pub fn App() -> impl IntoView { // if expires_in isn't 0, then set a timeout that rerfresh a minute short of the refresh. let expires_in = rw_expires_in.get(); if expires_in != 0 && email.get_untracked().is_some() { - let handle = set_timeout_with_handle( + let handle = set_timeout( move || { refresh_token.dispatch(RefreshToken { email: email.get_untracked().unwrap(), diff --git a/router/src/components.rs b/router/src/components.rs index a180c7f50a..fb693d0347 100644 --- a/router/src/components.rs +++ b/router/src/components.rs @@ -658,7 +658,7 @@ pub fn RoutingProgress( move |prev: Option>| { if is_routing.get() && !is_showing.get() { set_is_showing.set(true); - set_interval_with_handle( + set_interval( move || { set_progress.update(|n| *n += percent_per_increment); }, @@ -670,7 +670,7 @@ pub fn RoutingProgress( prev? } else { set_progress.set(100.0); - set_timeout( + _ = set_timeout( move || { set_progress.set(0.0); set_is_showing.set(false); diff --git a/router/src/hooks.rs b/router/src/hooks.rs index ff5cf2454a..1dfd3bba70 100644 --- a/router/src/hooks.rs +++ b/router/src/hooks.rs @@ -131,14 +131,14 @@ where if !IS_NAVIGATING.load(Ordering::Relaxed) { IS_NAVIGATING.store(true, Ordering::Relaxed); - request_animation_frame({ + _ = request_animation_frame({ let navigate = navigate.clone(); let nav_options = nav_options.clone(); move || { navigate(&new_url, nav_options.clone()); IS_NAVIGATING.store(false, Ordering::Relaxed) } - }) + }); } }); diff --git a/router/src/location/history.rs b/router/src/location/history.rs index c7cdfc85dc..e170d040a4 100644 --- a/router/src/location/history.rs +++ b/router/src/location/history.rs @@ -259,7 +259,7 @@ impl LocationProvider for BrowserUrl { if url.origin() == current_origin { let navigate = navigate.clone(); // delay by a tick here, so that the Action updates *before* the redirect - request_animation_frame(move || { + _ = request_animation_frame(move || { navigate(&url.href(), Default::default()); }); // Use set_href() if the conditions for client-side navigation were not satisfied