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

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

Issue 2795623002: MD Bookmarks: Handle bookmark creation (Closed)
Patch Set: Update test 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..c3e820e60f84217f78428b1fbe706c4cf8505ac6 100644
--- a/chrome/browser/resources/md_bookmarks/util.js
+++ b/chrome/browser/resources/md_bookmarks/util.js
@@ -19,6 +19,26 @@ cr.define('bookmarks.util', function() {
}
/**
+ * @param {BookmarkTreeNode} treeNode
+ * @return {BookmarkNode}
+ */
+ function normalizeNode(treeNode) {
+ var node = Object.assign({}, treeNode);
+ // Node index is not necessary and not kept up-to-date. Remove it from the
+ // data structure so we don't accidentally depend on the incorrect
+ // information.
+ delete node.index;
+
+ if (!('url' in node)) {
+ // The onCreated API listener returns folders without |children| defined.
+ node.children = (node.children || []).map(function(child) {
+ return child.id;
+ });
+ }
+ return /** @type {BookmarkNode} */ (node);
+ }
+
+ /**
* @param {BookmarkTreeNode} rootNode
* @return {NodeList}
*/
@@ -30,20 +50,13 @@ cr.define('bookmarks.util', function() {
while (stack.length > 0) {
var node = stack.pop();
- // Node index is not necessary and not kept up-to-date. Remove it from the
- // data structure so we don't accidentally depend on the incorrect
- // information.
- delete node.index;
- nodeList[node.id] = node;
+ nodeList[node.id] = normalizeNode(node);
if (!node.children)
continue;
- var childIds = [];
node.children.forEach(function(child) {
- childIds.push(child.id);
stack.push(child);
});
- node.children = childIds;
}
return nodeList;
@@ -94,6 +107,7 @@ cr.define('bookmarks.util', function() {
getDisplayedList: getDisplayedList,
hasChildFolders: hasChildFolders,
isShowingSearch: isShowingSearch,
+ normalizeNode: normalizeNode,
normalizeNodes: normalizeNodes,
};
});
« no previous file with comments | « chrome/browser/resources/md_bookmarks/reducers.js ('k') | chrome/test/data/webui/md_bookmarks/reducers_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698