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

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

Issue 2946203002: MD Bookmarks: Batch updates to the UI when processing deletes and moves (Closed)
Patch Set: Batch in API listener Created 3 years, 6 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/store.js
diff --git a/chrome/browser/resources/md_bookmarks/store.js b/chrome/browser/resources/md_bookmarks/store.js
index 9b47de1b91687ce520be82164ea3576fe4b98721..7cbf93d854a8d4cfc11d1207ec6d922ec9118bbf 100644
--- a/chrome/browser/resources/md_bookmarks/store.js
+++ b/chrome/browser/resources/md_bookmarks/store.js
@@ -19,6 +19,8 @@ cr.define('bookmarks', function() {
this.queuedActions_ = [];
/** @type {!Array<!StoreObserver>} */
this.observers_ = [];
+ /** @private {boolean} */
+ this.batchMode_ = false;
}
Store.prototype = {
@@ -57,6 +59,25 @@ cr.define('bookmarks', function() {
this.observers_.splice(index, 1);
},
+ /**
+ * Begin a batch update to store data, which will disable updates to the
+ * UI until `endBatchUpdate` is called. This is useful when a single UI
+ * operation is likely to cause many sequential model updates (eg, deleting
+ * 100 bookmarks).
+ */
+ beginBatchUpdate: function() {
+ this.batchMode_ = true;
+ },
+
+ /**
+ * End a batch update to the store data, notifying the UI of any changes
+ * which occurred while batch mode was enabled.
+ */
+ endBatchUpdate: function() {
+ this.batchMode_ = false;
+ this.notifyObservers_(this.data);
+ },
+
/**
* Handles a 'deferred' action, which can asynchronously dispatch actions
* to the Store in order to reach a new UI state. DeferredActions have the
@@ -104,7 +125,7 @@ cr.define('bookmarks', function() {
this.data_ = bookmarks.reduceAction(this.data_, action);
// Batch notifications until after all initialization queuedActions are
// resolved.
- if (this.isInitialized())
+ if (this.isInitialized() && !this.batchMode_)
this.notifyObservers_(this.data_);
},
« no previous file with comments | « chrome/browser/resources/md_bookmarks/api_listener.js ('k') | chrome/test/data/webui/md_bookmarks/md_bookmarks_browsertest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698