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

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

Issue 2733463002: MD Bookmarks: Add basic page features to new data-flow system (Closed)
Patch Set: calamity@ review Created 3 years, 9 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
new file mode 100644
index 0000000000000000000000000000000000000000..3bc47038343be1422a05104cb936f6e8d99fd911
--- /dev/null
+++ b/chrome/browser/resources/md_bookmarks/util.js
@@ -0,0 +1,63 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+/**
+ * @fileoverview Utility functions for the Bookmarks page.
+ */
+
+cr.define('bookmarks.util', function() {
+ /**
+ * @param {!BookmarksPageState} state
+ * @return {!Array<string>}
+ */
+ function getDisplayedList(state) {
+ return assert(state.nodes[assert(state.selectedFolder)].children);
+ }
+
+ /**
+ * @param {BookmarkTreeNode} rootNode
+ * @return {NodeList}
+ */
+ function normalizeNodes(rootNode) {
+ /** @type {NodeList} */
+ var nodeList = {};
+ var stack = [];
+ stack.push(rootNode);
+
+ 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;
+ if (!node.children)
+ continue;
+
+ var childIds = [];
+ node.children.forEach(function(child) {
+ childIds.push(child.id);
+ stack.push(child);
+ });
+ node.children = childIds;
+ }
+
+ return nodeList;
+ }
+
+ /** @return {!BookmarksPageState} */
+ function createEmptyState() {
+ return {
+ nodes: {},
+ selectedFolder: '0',
+ closedFolders: {},
+ };
+ }
+
+ return {
+ createEmptyState: createEmptyState,
+ getDisplayedList: getDisplayedList,
+ normalizeNodes: normalizeNodes,
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698