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

Side by Side Diff: chrome/browser/resources/md_bookmarks/util.js

Issue 2733463002: MD Bookmarks: Add basic page features to new data-flow system (Closed)
Patch Set: Rebase 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 /**
6 * @fileoverview Utility functions for the Bookmarks page.
7 */
8
9 cr.define('bookmarks.util', function() {
10 /**
11 * @param {!BookmarksPageState} state
12 * @return {!Array<string>}
13 */
14 function getDisplayedList(state) {
15 return assert(state.nodes[assert(state.selectedFolder)].children);
calamity 2017/03/07 07:27:35 Does this remove the 'unselected sidebar during se
tsergeant 2017/03/08 02:47:10 The plan is that the sidebar will be unselected du
16 }
17
18 /**
19 * @param {BookmarkTreeNode} rootNode
20 * @return {NodeList}
21 */
22 function normalizeNodes(rootNode) {
23 /** @type {NodeList} */
24 var nodeMap = {};
calamity 2017/03/07 07:27:35 nit: nodeList?
tsergeant 2017/03/08 02:47:11 Done.
25 var queue = [];
calamity 2017/03/07 07:27:35 Looks more like a stack to me. Jus sayin'.
tsergeant 2017/03/08 02:47:10 Done.
26 queue.push(rootNode);
27
28 while (queue.length > 0) {
29 var node = queue.pop();
30 // Node index is not necessary and not kept up-to-date. Remove it from the
31 // data structure so we don't accidentally depend on the incorrect
32 // information.
33 delete node.index;
34 nodeMap[node.id] = node;
35 if (node.children) {
calamity 2017/03/07 07:27:35 nit: invert and early continue.
tsergeant 2017/03/08 02:47:10 Done.
36 var childIds = [];
37 node.children.forEach(function(child) {
38 childIds.push(child.id);
39 queue.push(child);
40 });
41 node.children = childIds;
42 }
43 }
44
45 return nodeMap;
46 }
47
48 /** @return {!BookmarksPageState} */
49 function createEmptyState() {
50 return {
51 nodes: {},
52 selectedFolder: '0',
53 closedFolders: {},
54 };
55 }
56
57 return {
58 createEmptyState: createEmptyState,
59 getDisplayedList: getDisplayedList,
60 normalizeNodes: normalizeNodes,
61 };
62 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698