mediawiki-extensions-Popups/src/reducers/settings.js
joakin e6081106f1 Use EcmaScript modules instead of common.js modules
Why: Because they are the approved standard by TC39 and Ecma for
JavaScript modules.

Changes:
  * Wrap mw-node-qunit in run.js to register babel to transpile modules
    for node v6
  * Change all sources in src/ to use ES modules
    * Change constants.js to be able to run without
      jQuery.bracketedDevicePixelRatio given ES modules are hoisted to
      the top by spec so we can't patch globals before importing it
  * Change all tests in tests/node-qunit/ to use ES modules
  * Drop usage of mock-require given ES modules are easy to stub with
    sinon

Additional changes:
  * Rename tests/node-qunit/renderer.js to renderer.test.js to follow
    the convention of all the other files
  * Make npm run test:node run only .test.js test files so that it
    doesn't run the stubs.js or run.js file.

Bug: T171951
Change-Id: I17a0b76041d5e2fd18e2d54950d9d7c0db99a941
2017-07-31 23:05:44 +00:00

57 lines
1.4 KiB
JavaScript

import actionTypes from '../actionTypes';
import nextState from './nextState';
/**
* Reducer for actions that modify the state of the settings
*
* @param {Object} state
* @param {Object} action
* @return {Object} state after action
*/
export default function settings( state, action ) {
if ( state === undefined ) {
state = {
shouldShow: false,
showHelp: false,
shouldShowFooterLink: false
};
}
switch ( action.type ) {
case actionTypes.SETTINGS_SHOW:
return nextState( state, {
shouldShow: true,
showHelp: false
} );
case actionTypes.SETTINGS_HIDE:
return nextState( state, {
shouldShow: false,
showHelp: false
} );
case actionTypes.SETTINGS_CHANGE:
return action.wasEnabled === action.enabled ?
// If the setting is the same, just hide the dialogs
nextState( state, {
shouldShow: false
} ) :
// If the settings have changed...
nextState( state, {
// If we enabled, we just hide directly, no help
// If we disabled, keep it showing and let the ui show the help.
shouldShow: !action.enabled,
showHelp: !action.enabled,
// Since the footer link is only ever shown to anonymous users (see
// the BOOT case below), state.userIsAnon is always truthy here.
shouldShowFooterLink: !action.enabled
} );
case actionTypes.BOOT:
return nextState( state, {
shouldShowFooterLink: action.user.isAnon && !action.isEnabled
} );
default:
return state;
}
}