Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2560)

Unified Diff: chrome/browser/resources/md_bookmarks/timer_proxy.js

Issue 2977523002: MD Bookmarks: Scroll and select items that are added to the main list (Closed)
Patch Set: Add debouncer, rebase past DND change Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/md_bookmarks/timer_proxy.js
diff --git a/chrome/browser/resources/md_bookmarks/timer_proxy.js b/chrome/browser/resources/md_bookmarks/timer_proxy.js
index de96c7fdb4ec7aa2b5bfe9c2329ccaff095de13f..88ae8762f58fdd07aa2f094162042e30f8f0c274 100644
--- a/chrome/browser/resources/md_bookmarks/timer_proxy.js
+++ b/chrome/browser/resources/md_bookmarks/timer_proxy.js
@@ -27,7 +27,51 @@ cr.define('bookmarks', function() {
},
};
+ /**
+ * A timer which will fire on the next task after the last time it is reset.
calamity 2017/07/26 05:36:06 nit: This isn't strictly true. It gets added to th
tsergeant 2017/07/26 06:34:07 Done.
+ * @param {function()} callback
+ * @constructor
+ */
+ function Debouncer(callback) {
tsergeant 2017/07/25 00:13:00 I'm happy enough with this for now, but one unansw
calamity 2017/07/26 05:36:06 Acknowledged.
+ this.callback_ = callback;
+ this.timerProxy_ = new TimerProxy();
+ this.timer_ = null;
+ this.boundTimerCallback_ = this.timerCallback_.bind(this);
+ this.isDone_ = false;
+ this.promiseResolver_ = new PromiseResolver();
calamity 2017/07/26 05:36:06 nit: Couple of types?
tsergeant 2017/07/26 06:34:07 Done.
+ }
+
+ Debouncer.prototype = {
+ resetTimer: function() {
calamity 2017/07/26 05:36:06 nit: resetTimeout perhaps? This will be given a de
tsergeant 2017/07/26 06:34:07 Done.
+ if (this.timer_)
+ this.timerProxy_.clearTimeout(this.timer_);
+ this.timer_ = this.timerProxy_.setTimeout(this.boundTimerCallback_);
+ },
+
+ /**
+ * @return {boolean} True if the Debouncer has finished processing.
+ */
+ done: function() {
+ return this.isDone_;
+ },
+
+ /**
+ * @return {Promise} Promise which resolves immediately after the callback.
+ */
+ get promise() {
+ return this.promiseResolver_.promise;
+ },
+
+ /** @private */
+ timerCallback_: function() {
+ this.isDone_ = true;
+ this.callback_.call();
+ this.promiseResolver_.resolve();
+ },
+ };
+
return {
+ Debouncer: Debouncer,
TimerProxy: TimerProxy,
};
});

Powered by Google App Engine
This is Rietveld 408576698