| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 items: new Set(), | 48 items: new Set(), |
| 49 anchor: null, | 49 anchor: null, |
| 50 }; | 50 }; |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 /** | 53 /** |
| 54 * @param {SelectionState} selectionState | 54 * @param {SelectionState} selectionState |
| 55 * @param {!Set<string>} deleted | 55 * @param {!Set<string>} deleted |
| 56 * @return SelectionState | 56 * @return SelectionState |
| 57 */ | 57 */ |
| 58 SelectionState.deselectDeletedItems = function(selectionState, deleted) { | 58 SelectionState.deselectItems = 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 | 68 * @param {SelectionState} selectionState |
| (...skipping 14 matching lines...) Expand all Loading... |
| 83 SelectionState.updateSelection = function(selection, action) { | 83 SelectionState.updateSelection = function(selection, action) { |
| 84 switch (action.name) { | 84 switch (action.name) { |
| 85 case 'clear-search': | 85 case 'clear-search': |
| 86 case 'finish-search': | 86 case 'finish-search': |
| 87 case 'select-folder': | 87 case 'select-folder': |
| 88 case 'deselect-items': | 88 case 'deselect-items': |
| 89 return SelectionState.deselectAll(selection); | 89 return SelectionState.deselectAll(selection); |
| 90 case 'select-items': | 90 case 'select-items': |
| 91 return SelectionState.selectItems(selection, action); | 91 return SelectionState.selectItems(selection, action); |
| 92 case 'remove-bookmark': | 92 case 'remove-bookmark': |
| 93 return SelectionState.deselectDeletedItems( | 93 return SelectionState.deselectItems(selection, action.descendants); |
| 94 selection, action.descendants); | 94 case 'move-bookmark': |
| 95 // Deselect items when they are moved to another folder, since they will |
| 96 // no longer be visible on screen (for simplicity, ignores items visible |
| 97 // in search results). |
| 98 if (action.parentId != action.oldParentId && |
| 99 selection.items.has(action.id)) { |
| 100 return SelectionState.deselectItems(selection, new Set([action.id])); |
| 101 } |
| 102 return selection; |
| 95 case 'update-anchor': | 103 case 'update-anchor': |
| 96 return SelectionState.updateAnchor(selection, action); | 104 return SelectionState.updateAnchor(selection, action); |
| 97 default: | 105 default: |
| 98 return selection; | 106 return selection; |
| 99 } | 107 } |
| 100 }; | 108 }; |
| 101 | 109 |
| 102 var SearchState = {}; | 110 var SearchState = {}; |
| 103 | 111 |
| 104 /** | 112 /** |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 468 return { | 476 return { |
| 469 reduceAction: reduceAction, | 477 reduceAction: reduceAction, |
| 470 ClosedFolderState: ClosedFolderState, | 478 ClosedFolderState: ClosedFolderState, |
| 471 NodeState: NodeState, | 479 NodeState: NodeState, |
| 472 PreferencesState: PreferencesState, | 480 PreferencesState: PreferencesState, |
| 473 SearchState: SearchState, | 481 SearchState: SearchState, |
| 474 SelectedFolderState: SelectedFolderState, | 482 SelectedFolderState: SelectedFolderState, |
| 475 SelectionState: SelectionState, | 483 SelectionState: SelectionState, |
| 476 }; | 484 }; |
| 477 }); | 485 }); |
| OLD | NEW |