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

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

Issue 2741393002: MD Bookmarks: Implement item selection in new data flow system (Closed)
Patch Set: 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
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 ca13ab5cd7c1e820662349656f45aae15251c25a..05d6262905fd490dda07dabc298d70027fcbfb5d 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 newState = {};
calamity 2017/03/14 03:01:45 nit: newItems
tsergeant 2017/03/14 05:42:02 Done.
+ if (action.add)
+ Object.assign(newState, selectionState.items);
+
+ action.items.forEach(function(id) {
+ newState[id] = true;
+ });
+
+ return /** @type {SelectionState} */ (Object.assign({}, selectionState, {
+ items: newState,
+ anchor: action.anchor,
+ }));
+ };
+
+ /**
+ * @param {SelectionState} selectionState
+ * @return {SelectionState}
+ */
+ SelectionState.deselectAll = function(selectionState) {
+ return {
+ count: 0,
calamity 2017/03/14 03:01:45 Is count used anywhere? Or is it just like, a #def
tsergeant 2017/03/14 05:42:02 I kept meaning to either implement it or remove it
+ items: {},
+ anchor: null,
+ };
+ };
+
+ /**
+ * @param {SelectionState} selection
+ * @param {Action} action
+ * @return {SelectionState}
+ */
+ SelectionState.updateSelection = function(selection, action) {
+ switch (action.name) {
+ case 'select-folder':
+ case 'finish-search':
calamity 2017/03/14 03:01:45 Also clear-search. +Test
tsergeant 2017/03/14 05:42:02 Done.
+ return SelectionState.deselectAll(selection);
+ case 'select-items':
+ return SelectionState.selectItems(selection, action);
calamity 2017/03/14 03:01:45 What happens to removed anchor indexes? They'll ex
tsergeant 2017/03/14 05:42:02 Yup, again, that's something that's was fixed in t
+ }
+ return selection;
+ };
+
var SearchState = {};
/**
@@ -243,6 +293,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),
};
}
@@ -252,5 +303,6 @@ cr.define('bookmarks', function() {
NodeState: NodeState,
SearchState: SearchState,
SelectedFolderState: SelectedFolderState,
+ SelectionState: SelectionState,
};
});

Powered by Google App Engine
This is Rietveld 408576698