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

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: 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 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);
16 }
17
18 /**
19 * @param {BookmarkTreeNode} rootNode
20 * @return {NodeList}
21 */
22 function normalizeNodes(rootNode) {
23 /** @type {NodeList} */
24 var nodeList = {};
25 var stack = [];
26 stack.push(rootNode);
27
28 while (stack.length > 0) {
29 var node = stack.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 nodeList[node.id] = node;
35 if (!node.children)
36 continue;
37
38 var childIds = [];
39 node.children.forEach(function(child) {
40 childIds.push(child.id);
41 stack.push(child);
42 });
43 node.children = childIds;
44 }
45
46 return nodeList;
47 }
48
49 /** @return {!BookmarksPageState} */
50 function createEmptyState() {
51 return {
52 nodes: {},
53 selectedFolder: '0',
54 closedFolders: {},
55 };
56 }
57
58 return {
59 createEmptyState: createEmptyState,
60 getDisplayedList: getDisplayedList,
61 normalizeNodes: normalizeNodes,
62 };
63 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698