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

Unified Diff: chrome/browser/resources/md_bookmarks/api_listener.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
« no previous file with comments | « no previous file | chrome/browser/resources/md_bookmarks/store.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/md_bookmarks/api_listener.js
diff --git a/chrome/browser/resources/md_bookmarks/api_listener.js b/chrome/browser/resources/md_bookmarks/api_listener.js
index d7907a48876efd49cc3c78c991206a40c6ea1934..1e8852cbe7d587a12e13c8fe04c9ef2a0978a0bb 100644
--- a/chrome/browser/resources/md_bookmarks/api_listener.js
+++ b/chrome/browser/resources/md_bookmarks/api_listener.js
@@ -8,6 +8,27 @@
*/
cr.define('bookmarks.ApiListener', function() {
+
+ /** @type {?number} */
+ var timerHandle;
+
+ /**
+ * Batches UI updates so that no changes will be made to UI until the next
+ * task after the last call to this method. This is useful for listeners which
+ * can be called in a tight loop by UI actions.
+ */
+ function batchUIUpdates() {
+ if (timerHandle)
+ clearTimeout(timerHandle);
+ else
+ bookmarks.Store.getInstance().beginBatchUpdate();
+
+ timerHandle = setTimeout(function() {
+ bookmarks.Store.getInstance().endBatchUpdate();
+ timerHandle = null;
+ });
+ }
+
/** @param {Action} action */
function dispatch(action) {
bookmarks.Store.getInstance().dispatch(action);
@@ -26,6 +47,7 @@ cr.define('bookmarks.ApiListener', function() {
* @param {BookmarkTreeNode} treeNode
*/
function onBookmarkCreated(id, treeNode) {
+ batchUIUpdates();
dispatch(bookmarks.actions.createBookmark(id, treeNode));
}
@@ -34,6 +56,7 @@ cr.define('bookmarks.ApiListener', function() {
* @param {{parentId: string, index: number}} removeInfo
*/
function onBookmarkRemoved(id, removeInfo) {
+ batchUIUpdates();
var nodes = bookmarks.Store.getInstance().data.nodes;
dispatch(bookmarks.actions.removeBookmark(
id, removeInfo.parentId, removeInfo.index, nodes));
@@ -49,6 +72,7 @@ cr.define('bookmarks.ApiListener', function() {
* }} moveInfo
*/
function onBookmarkMoved(id, moveInfo) {
+ batchUIUpdates();
dispatch(bookmarks.actions.moveBookmark(
id, moveInfo.parentId, moveInfo.index, moveInfo.oldParentId,
moveInfo.oldIndex));
« no previous file with comments | « no previous file | chrome/browser/resources/md_bookmarks/store.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698