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

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

Issue 2885723002: [MD Bookmarks] Add keyboard navigation and selection to bookmark list. (Closed)
Patch Set: address comments Created 3 years, 7 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview Module of functions which produce a new page state in response 6 * @fileoverview Module of functions which produce a new page state in response
7 * to an action. Reducers (in the same sense as Array.prototype.reduce) must be 7 * to an action. Reducers (in the same sense as Array.prototype.reduce) must be
8 * pure functions: they must not modify existing state objects, or make any API 8 * pure functions: they must not modify existing state objects, or make any API
9 * calls. 9 * calls.
10 */ 10 */
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 SelectionState.deselectDeletedItems = function(selectionState, deleted) { 58 SelectionState.deselectDeletedItems = function(selectionState, deleted) {
59 return /** @type {SelectionState} */ Object.assign({}, selectionState, { 59 return /** @type {SelectionState} */ Object.assign({}, selectionState, {
60 items: bookmarks.util.removeIdsFromSet(selectionState.items, deleted), 60 items: bookmarks.util.removeIdsFromSet(selectionState.items, deleted),
61 anchor: !selectionState.anchor || deleted.has(selectionState.anchor) ? 61 anchor: !selectionState.anchor || deleted.has(selectionState.anchor) ?
62 null : 62 null :
63 selectionState.anchor, 63 selectionState.anchor,
64 }); 64 });
65 }; 65 };
66 66
67 /** 67 /**
68 * @param {SelectionState} selectionState
69 * @param {Action} action
70 * @return {SelectionState}
71 */
72 SelectionState.updateAnchor = function(selectionState, action) {
73 return /** @type {SelectionState} */ (Object.assign({}, selectionState, {
74 anchor: action.anchor,
75 }));
76 };
77
78 /**
68 * @param {SelectionState} selection 79 * @param {SelectionState} selection
69 * @param {Action} action 80 * @param {Action} action
70 * @return {SelectionState} 81 * @return {SelectionState}
71 */ 82 */
72 SelectionState.updateSelection = function(selection, action) { 83 SelectionState.updateSelection = function(selection, action) {
73 switch (action.name) { 84 switch (action.name) {
74 case 'clear-search': 85 case 'clear-search':
75 case 'finish-search': 86 case 'finish-search':
76 case 'select-folder': 87 case 'select-folder':
77 case 'deselect-items': 88 case 'deselect-items':
78 return SelectionState.deselectAll(selection); 89 return SelectionState.deselectAll(selection);
79 case 'select-items': 90 case 'select-items':
80 return SelectionState.selectItems(selection, action); 91 return SelectionState.selectItems(selection, action);
81 case 'remove-bookmark': 92 case 'remove-bookmark':
82 return SelectionState.deselectDeletedItems( 93 return SelectionState.deselectDeletedItems(
83 selection, action.descendants); 94 selection, action.descendants);
95 case 'update-anchor':
96 return SelectionState.updateAnchor(selection, action);
84 default: 97 default:
85 return selection; 98 return selection;
86 } 99 }
87 }; 100 };
88 101
89 var SearchState = {}; 102 var SearchState = {};
90 103
91 /** 104 /**
92 * @param {SearchState} search 105 * @param {SearchState} search
93 * @param {Action} action 106 * @param {Action} action
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 444
432 return { 445 return {
433 reduceAction: reduceAction, 446 reduceAction: reduceAction,
434 ClosedFolderState: ClosedFolderState, 447 ClosedFolderState: ClosedFolderState,
435 NodeState: NodeState, 448 NodeState: NodeState,
436 SearchState: SearchState, 449 SearchState: SearchState,
437 SelectedFolderState: SelectedFolderState, 450 SelectedFolderState: SelectedFolderState,
438 SelectionState: SelectionState, 451 SelectionState: SelectionState,
439 }; 452 };
440 }); 453 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/list.js ('k') | chrome/test/data/webui/md_bookmarks/item_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698