You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reducer.ts 912B

1234567891011121314151617181920212223242526272829303132333435
  1. import _ from 'lodash';
  2. import ReducerRegistry from '../redux/ReducerRegistry';
  3. import { UPDATE_FLAGS } from './actionTypes';
  4. /**
  5. * Default state value for the feature flags.
  6. */
  7. const DEFAULT_STATE = {};
  8. export interface IFlagsState {
  9. flags?: Object;
  10. }
  11. /**
  12. * Reduces redux actions which handle feature flags.
  13. *
  14. * @param {State} state - The current redux state.
  15. * @param {Action} action - The redux action to reduce.
  16. * @param {string} action.type - The type of the redux action to reduce.
  17. * @returns {State} The next redux state that is the result of reducing the
  18. * specified action.
  19. */
  20. ReducerRegistry.register('features/base/flags', (state: IFlagsState = DEFAULT_STATE, action) => {
  21. switch (action.type) {
  22. case UPDATE_FLAGS: {
  23. const newState = _.merge({}, state, action.flags);
  24. return _.isEqual(state, newState) ? state : newState;
  25. }
  26. }
  27. return state;
  28. });