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
|
||||
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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue