OLD | NEW |
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 Loading... |
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 Loading... |
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 }); |
OLD | NEW |