Simplify debounce function and increase timeout
This commit is contained in:
parent
85004ada3f
commit
1573341c18
1 changed files with 5 additions and 5 deletions
|
|
@ -280,11 +280,11 @@
|
||||||
always prefer to call the most recent call to `f` as close to the delay
|
always prefer to call the most recent call to `f` as close to the delay
|
||||||
as possible."
|
as possible."
|
||||||
[ms f]
|
[ms f]
|
||||||
(let [prev (volatile! (now))]
|
(let [timeout (volatile! nil)]
|
||||||
(fn debounced-fn [& args]
|
(fn debounced-fn [& args]
|
||||||
(when (< ms (- (now) @prev))
|
(when @timeout
|
||||||
(js/requestAnimationFrame #(apply f args)))
|
(js/clearTimeout @timeout))
|
||||||
(vreset! prev (now)))))
|
(vreset! timeout (js/setTimeout #(apply f args) ms)))))
|
||||||
|
|
||||||
(defn- refresh-displayed-posts!
|
(defn- refresh-displayed-posts!
|
||||||
[{:keys [per-page query]}]
|
[{:keys [per-page query]}]
|
||||||
|
|
@ -309,7 +309,7 @@
|
||||||
(assoc :displayed-posts displayed-posts)
|
(assoc :displayed-posts displayed-posts)
|
||||||
(update :loading disj refresh-id))))))))
|
(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
|
; 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.
|
; values change that serve as input to the current search reults.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue