Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/axum_js_ssr/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -693,7 +693,7 @@ fn CodeDemoWasm(mode: WasmDemo) -> impl IntoView {
<Suspense fallback=move || view! { <p>"Loading code example..."</p> }>{
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(...).
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -870,7 +870,7 @@ fn WasmBindgenEffect() -> impl IntoView {
let example = r#"<Suspense fallback=move || view! { <p>"Loading code example..."</p> }>{
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();
Expand Down
2 changes: 1 addition & 1 deletion examples/router/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fn delay(
duration: Duration,
) -> impl Future<Output = Result<(), Canceled>> + Send {
let (tx, rx) = oneshot::channel();
set_timeout(
_ = set_timeout(
move || {
_ = tx.send(());
},
Expand Down
2 changes: 1 addition & 1 deletion examples/timer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion leptos/src/animated_show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
4 changes: 2 additions & 2 deletions leptos_dom/examples/test-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,14 @@ where
let to = to.into_iter().collect::<Vec<_>>();

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);
}
Expand Down
68 changes: 8 additions & 60 deletions leptos_dom/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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<AnimationFrameRequestHandle, JsValue> {
#[cfg(feature = "tracing")]
Expand All @@ -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);
Expand All @@ -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.
Expand All @@ -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<IdleCallbackHandle, JsValue> {
#[cfg(feature = "tracing")]
Expand Down Expand Up @@ -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);

Expand All @@ -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).
///
Expand All @@ -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<TimeoutHandle, JsValue> {
Expand Down Expand Up @@ -391,7 +353,7 @@ pub fn debounce<T: 'static>(
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 || {
Expand All @@ -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).
Expand All @@ -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<IntervalHandle, JsValue> {
Expand Down
2 changes: 1 addition & 1 deletion projects/bevy3d_ui/src/routes/demo1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down
2 changes: 1 addition & 1 deletion projects/sso_auth_axum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
4 changes: 2 additions & 2 deletions router/src/components.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ pub fn RoutingProgress(
move |prev: Option<Option<IntervalHandle>>| {
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);
},
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions router/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
});
}
});

Expand Down
2 changes: 1 addition & 1 deletion router/src/location/history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading