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

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

Issue 2704983002: MD Bookmarks: Proof-of-concept reimplementation of data storage/binding layer (Closed)
Patch Set: Add doc comments Created 3 years, 10 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..9c1e942146e8e072d41d79e71f22a249c8983f79
--- /dev/null
+++ b/chrome/browser/resources/md_bookmarks/util.js
@@ -0,0 +1,75 @@
+// 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) {
+ if (state.selectedFolder)
+ return assert(state.nodes[state.selectedFolder].children);
+
+ return state.search.results;
+ }
+
+ /**
+ * @param {BookmarkTreeNode} rootNode
+ * @return {NodeList}
+ */
+ function normalizeNodes(rootNode) {
+ /** @type {NodeList} */
+ var nodeMap = {};
+ var queue = [];
+ queue.push(rootNode);
+
+ while (queue.length > 0) {
+ var node = queue.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;
+ nodeMap[node.id] = node;
+ if (node.children) {
+ var childIds = [];
+ node.children.forEach(function(child) {
+ childIds.push(child.id);
+ queue.push(child);
+ });
+ node.children = childIds;
+ }
+ }
+
+ return nodeMap;
+ }
+
+ /** @return {BookmarksPageState} */
+ function createEmptyState() {
+ return {
+ nodes: {},
+ selectedFolder: '0',
+ closedFolders: {},
+ search: {
+ term: '',
+ inProgress: false,
+ results: [],
+ },
+ selection: {
+ items: {},
+ anchor: null,
+ count: 0,
+ },
+ };
+ }
+
+ return {
+ createEmptyState: createEmptyState,
+ getDisplayedList: getDisplayedList,
+ normalizeNodes: normalizeNodes,
+ };
+});
« no previous file with comments | « chrome/browser/resources/md_bookmarks/util.html ('k') | chrome/browser/ui/webui/md_bookmarks/md_bookmarks_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698