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.