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

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

Issue 2902103002: MD Bookmarks: Disable 'Open in Incognito Window' when Incognito is disabled (Closed)
Patch Set: Review comment Created 3 years, 6 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 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 var closed = !action.open; 388 var closed = !action.open;
389 var newClosedFolders = new Set(closedFolders); 389 var newClosedFolders = new Set(closedFolders);
390 if (closed) 390 if (closed)
391 newClosedFolders.add(action.id); 391 newClosedFolders.add(action.id);
392 else 392 else
393 newClosedFolders.delete(action.id); 393 newClosedFolders.delete(action.id);
394 394
395 return newClosedFolders; 395 return newClosedFolders;
396 }; 396 };
397 397
398 var PreferencesState = {};
399
400 /**
401 * @param {PreferencesState} prefs
402 * @param {Action} action
403 * @return {PreferencesState}
404 */
405 PreferencesState.updatePrefs = function(prefs, action) {
406 switch (action.name) {
407 case 'set-incognito-availability':
408 return /** @type {PreferencesState} */ (Object.assign({}, prefs, {
409 incognitoAvailability: action.value,
410 }));
411 default:
412 return prefs;
413 }
414 };
415
398 /** 416 /**
399 * @param {ClosedFolderState} closedFolders 417 * @param {ClosedFolderState} closedFolders
400 * @param {Action} action 418 * @param {Action} action
401 * @param {NodeMap} nodes 419 * @param {NodeMap} nodes
402 * @return {ClosedFolderState} 420 * @return {ClosedFolderState}
403 */ 421 */
404 ClosedFolderState.updateClosedFolders = function( 422 ClosedFolderState.updateClosedFolders = function(
405 closedFolders, action, nodes) { 423 closedFolders, action, nodes) {
406 switch (action.name) { 424 switch (action.name) {
407 case 'change-folder-open': 425 case 'change-folder-open':
(...skipping 22 matching lines...) Expand all
430 * @param {Action} action 448 * @param {Action} action
431 * @return {!BookmarksPageState} 449 * @return {!BookmarksPageState}
432 */ 450 */
433 function reduceAction(state, action) { 451 function reduceAction(state, action) {
434 return { 452 return {
435 nodes: NodeState.updateNodes(state.nodes, action), 453 nodes: NodeState.updateNodes(state.nodes, action),
436 selectedFolder: SelectedFolderState.updateSelectedFolder( 454 selectedFolder: SelectedFolderState.updateSelectedFolder(
437 state.selectedFolder, action, state.nodes), 455 state.selectedFolder, action, state.nodes),
438 closedFolders: ClosedFolderState.updateClosedFolders( 456 closedFolders: ClosedFolderState.updateClosedFolders(
439 state.closedFolders, action, state.nodes), 457 state.closedFolders, action, state.nodes),
458 prefs: PreferencesState.updatePrefs(state.prefs, action),
440 search: SearchState.updateSearch(state.search, action), 459 search: SearchState.updateSearch(state.search, action),
441 selection: SelectionState.updateSelection(state.selection, action), 460 selection: SelectionState.updateSelection(state.selection, action),
442 }; 461 };
443 } 462 }
444 463
445 return { 464 return {
446 reduceAction: reduceAction, 465 reduceAction: reduceAction,
447 ClosedFolderState: ClosedFolderState, 466 ClosedFolderState: ClosedFolderState,
448 NodeState: NodeState, 467 NodeState: NodeState,
468 PreferencesState: PreferencesState,
449 SearchState: SearchState, 469 SearchState: SearchState,
450 SelectedFolderState: SelectedFolderState, 470 SelectedFolderState: SelectedFolderState,
451 SelectionState: SelectionState, 471 SelectionState: SelectionState,
452 }; 472 };
453 }); 473 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/constants.js ('k') | chrome/browser/resources/md_bookmarks/types.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698