From 1573341c18d1254b1672713e7f33427762c4d5e6 Mon Sep 17 00:00:00 2001 From: arne Date: Sat, 22 Nov 2025 00:09:52 +0100 Subject: [PATCH] Simplify debounce function and increase timeout --- src/computersandblues/lodestone/app.cljs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/computersandblues/lodestone/app.cljs b/src/computersandblues/lodestone/app.cljs index c181fce..b97af00 100644 --- a/src/computersandblues/lodestone/app.cljs +++ b/src/computersandblues/lodestone/app.cljs @@ -280,11 +280,11 @@ always prefer to call the most recent call to `f` as close to the delay as possible." [ms f] - (let [prev (volatile! (now))] + (let [timeout (volatile! nil)] (fn debounced-fn [& args] - (when (< ms (- (now) @prev)) - (js/requestAnimationFrame #(apply f args))) - (vreset! prev (now))))) + (when @timeout + (js/clearTimeout @timeout)) + (vreset! timeout (js/setTimeout #(apply f args) ms))))) (defn- refresh-displayed-posts! [{:keys [per-page query]}] @@ -309,7 +309,7 @@ (assoc :displayed-posts displayed-posts) (update :loading disj refresh-id)))))))) -(def debounced-refresh! (debounce 48 refresh-displayed-posts!)) +(defonce debounced-refresh! (debounce (* 16 16) refresh-displayed-posts!)) ; we use reagent's machinery below to define a callback that runs whenever the ; values change that serve as input to the current search reults.