Simplify debounce function and increase timeout

This commit is contained in:
arne 2025-11-22 00:09:52 +01:00
commit 1573341c18

View file

@ -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.