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_); |
}, |