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

Unified Diff: chrome/browser/resources/md_bookmarks/reducers.js

Issue 2741393002: MD Bookmarks: Implement item selection in new data flow system (Closed)
Patch Set: Review 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/md_bookmarks/item.js ('k') | chrome/browser/resources/md_bookmarks/types.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/md_bookmarks/reducers.js
diff --git a/chrome/browser/resources/md_bookmarks/reducers.js b/chrome/browser/resources/md_bookmarks/reducers.js
index 629017b21a1d806e8b8a0ef2d13ba761f72ba49d..901203cd1609bdc9d807cbc6942e20b65c75b8f9 100644
--- a/chrome/browser/resources/md_bookmarks/reducers.js
+++ b/chrome/browser/resources/md_bookmarks/reducers.js
@@ -10,6 +10,56 @@
*/
cr.define('bookmarks', function() {
+ var SelectionState = {};
+
+ /**
+ * @param {SelectionState} selectionState
+ * @param {Action} action
+ * @return {SelectionState}
+ */
+ SelectionState.selectItems = function(selectionState, action) {
+ var newItems = {};
+ if (action.add)
+ Object.assign(newItems, selectionState.items);
+
+ action.items.forEach(function(id) {
+ newItems[id] = true;
+ });
+
+ return /** @type {SelectionState} */ (Object.assign({}, selectionState, {
+ items: newItems,
+ anchor: action.anchor,
+ }));
+ };
+
+ /**
+ * @param {SelectionState} selectionState
+ * @return {SelectionState}
+ */
+ SelectionState.deselectAll = function(selectionState) {
+ return {
+ items: {},
+ anchor: null,
+ };
+ };
+
+ /**
+ * @param {SelectionState} selection
+ * @param {Action} action
+ * @return {SelectionState}
+ */
+ SelectionState.updateSelection = function(selection, action) {
+ switch (action.name) {
+ case 'clear-search':
+ case 'finish-search':
+ case 'select-folder':
+ return SelectionState.deselectAll(selection);
+ case 'select-items':
+ return SelectionState.selectItems(selection, action);
+ }
+ return selection;
+ };
+
var SearchState = {};
/**
@@ -181,52 +231,53 @@ cr.define('bookmarks', function() {
var ClosedFolderState = {};
/**
- * @param {ClosedFolderState} state
+ * @param {ClosedFolderState} closedFolders
* @param {Action} action
* @param {NodeList} nodes
* @return {ClosedFolderState}
*/
- ClosedFolderState.openAncestorsOf = function(state, action, nodes) {
+ ClosedFolderState.openAncestorsOf = function(closedFolders, action, nodes) {
var id = action.id;
var modifications = {};
var parentId = nodes[id].parentId;
while (parentId) {
- if (state[parentId]) {
+ if (closedFolders[parentId]) {
modifications[parentId] = false;
}
parentId = nodes[parentId].parentId;
}
- return Object.assign({}, state, modifications);
+ return Object.assign({}, closedFolders, modifications);
};
/**
- * @param {ClosedFolderState} state
+ * @param {ClosedFolderState} closedFolders
* @param {Action} action
* @return {ClosedFolderState}
*/
- ClosedFolderState.changeFolderOpen = function(state, action) {
+ ClosedFolderState.changeFolderOpen = function(closedFolders, action) {
var closed = !action.open;
var modification = {};
modification[action.id] = closed;
- return Object.assign({}, state, modification);
+ return Object.assign({}, closedFolders, modification);
};
/**
- * @param {ClosedFolderState} state
+ * @param {ClosedFolderState} closedFolders
* @param {Action} action
* @param {NodeList} nodes
* @return {ClosedFolderState}
*/
- ClosedFolderState.updateClosedFolders = function(state, action, nodes) {
+ ClosedFolderState.updateClosedFolders = function(
+ closedFolders, action, nodes) {
switch (action.name) {
case 'change-folder-open':
- return ClosedFolderState.changeFolderOpen(state, action);
+ return ClosedFolderState.changeFolderOpen(closedFolders, action);
case 'select-folder':
- return ClosedFolderState.openAncestorsOf(state, action, nodes);
+ return ClosedFolderState.openAncestorsOf(closedFolders, action, nodes);
default:
- return state;
+ return closedFolders;
};
};
@@ -245,6 +296,7 @@ cr.define('bookmarks', function() {
closedFolders: ClosedFolderState.updateClosedFolders(
state.closedFolders, action, state.nodes),
search: SearchState.updateSearch(state.search, action),
+ selection: SelectionState.updateSelection(state.selection, action),
};
}
@@ -254,5 +306,6 @@ cr.define('bookmarks', function() {
NodeState: NodeState,
SearchState: SearchState,
SelectedFolderState: SelectedFolderState,
+ SelectionState: SelectionState,
};
});
« no previous file with comments | « chrome/browser/resources/md_bookmarks/item.js ('k') | chrome/browser/resources/md_bookmarks/types.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698