-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix performance of auto-scrolling epoch navigation with debounce
- Loading branch information
1 parent
8e314fa
commit 560fceb
Showing
5 changed files
with
57 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
(ns day8.re-frame-10x.fx.debounce | ||
(:require | ||
[day8.re-frame-10x.inlined-deps.re-frame.v1v1v2.re-frame.core :as rf])) | ||
|
||
(defn now [] (.getTime (js/Date.))) | ||
|
||
(def registered-keys (atom nil)) | ||
|
||
(defn dispatch-if-not-superceded [{:keys [key delay event time-received]}] | ||
(when (= time-received (get @registered-keys key)) | ||
;; no new events on this key! | ||
(rf/dispatch event))) | ||
|
||
(defn dispatch-later [{:keys [delay] :as debounce}] | ||
(js/setTimeout | ||
(fn [] (dispatch-if-not-superceded debounce)) | ||
delay)) | ||
|
||
(rf/reg-fx | ||
::dispatch | ||
(fn dispatch-debounce [{:keys [key event delay] :as debounce}] | ||
(when (not (and (keyword? key) (vector? event) (integer? delay))) | ||
(rf/console :error "re-frame-10x ::debounce/dispatch invalid argument")) | ||
(let [ts (now)] | ||
(swap! registered-keys assoc (:key debounce) ts) | ||
(dispatch-later (assoc debounce :time-received ts))))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
(ns day8.re-frame-10x.fx.scroll | ||
(:require | ||
[day8.re-frame-10x.inlined-deps.re-frame.v1v1v2.re-frame.core :as rf])) | ||
|
||
(rf/reg-fx | ||
::into-view | ||
(fn [{:keys [js-dom]}] | ||
(when (instance? js/Element js-dom) | ||
(.scrollIntoView js-dom)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters