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

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

Issue 2752223004: MD Bookmarks: Remove deleted nodes from state tree (Closed)
Patch Set: Rebase Created 3 years, 8 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/util.js
diff --git a/chrome/browser/resources/md_bookmarks/util.js b/chrome/browser/resources/md_bookmarks/util.js
index 26d209f0c20cb972cf8ca66e5dce4852ab789fe8..4ca5f45555df5e79377165db4fb6ac73882b5eae 100644
--- a/chrome/browser/resources/md_bookmarks/util.js
+++ b/chrome/browser/resources/md_bookmarks/util.js
@@ -89,11 +89,72 @@ cr.define('bookmarks.util', function() {
return false;
}
+ /**
+ * Get all descendants of a node, including the node itself.
+ * @param {NodeList} nodes
+ * @param {string} baseId
+ * @return {!Set<string>}
+ */
+ function getDescendants(nodes, baseId) {
+ var descendants = new Set();
+ var stack = [];
+ stack.push(baseId);
+
+ while (stack.length > 0) {
+ var id = stack.pop();
+ var node = nodes[id];
+
+ if (!node)
+ continue;
+
+ descendants.add(id);
+
+ if (!node.children)
+ continue;
+
+ node.children.forEach(function(childId) {
+ stack.push(childId);
+ });
+ }
+
+ return descendants;
+ }
+
+ /**
+ * @param {!Object<string, T>} map
+ * @param {!Set<string>} ids
+ * @return {!Object<string, T>}
+ * @template T
+ */
+ function removeIdsFromMap(map, ids) {
+ var newMap = Object.assign({}, map);
+ ids.forEach(function(id) {
+ delete newMap[id];
+ });
+ return newMap;
+ }
+
+ /**
+ * @param {!Set<string>} set
+ * @param {!Set<string>} ids
+ * @return {!Set<string>}
+ */
+ function removeIdsFromSet(set, ids) {
+ var difference = new Set(set);
+ ids.forEach(function(id) {
+ difference.delete(id);
+ });
+ return difference;
+ }
+
return {
createEmptyState: createEmptyState,
+ getDescendants: getDescendants,
getDisplayedList: getDisplayedList,
hasChildFolders: hasChildFolders,
isShowingSearch: isShowingSearch,
normalizeNodes: normalizeNodes,
+ removeIdsFromMap: removeIdsFromMap,
+ removeIdsFromSet: removeIdsFromSet,
};
});
« no previous file with comments | « chrome/browser/resources/md_bookmarks/store_client.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