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

Side by Side 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, 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 if (state.selectedFolder)
16 return assert(state.nodes[state.selectedFolder].children);
17
18 return state.search.results;
19 }
20
21 /**
22 * @param {BookmarkTreeNode} rootNode
23 * @return {NodeList}
24 */
25 function normalizeNodes(rootNode) {
26 /** @type {NodeList} */
27 var nodeMap = {};
28 var queue = [];
29 queue.push(rootNode);
30
31 while (queue.length > 0) {
32 var node = queue.pop();
33 // Node index is not necessary and not kept up-to-date. Remove it from the
34 // data structure so we don't accidentally depend on the incorrect
35 // information.
36 delete node.index;
37 nodeMap[node.id] = node;
38 if (node.children) {
39 var childIds = [];
40 node.children.forEach(function(child) {
41 childIds.push(child.id);
42 queue.push(child);
43 });
44 node.children = childIds;
45 }
46 }
47
48 return nodeMap;
49 }
50
51 /** @return {BookmarksPageState} */
52 function createEmptyState() {
53 return {
54 nodes: {},
55 selectedFolder: '0',
56 closedFolders: {},
57 search: {
58 term: '',
59 inProgress: false,
60 results: [],
61 },
62 selection: {
63 items: {},
64 anchor: null,
65 count: 0,
66 },
67 };
68 }
69
70 return {
71 createEmptyState: createEmptyState,
72 getDisplayedList: getDisplayedList,
73 normalizeNodes: normalizeNodes,
74 };
75 });
OLDNEW
« 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