2019-05-24 11:06:05 +00:00
|
|
|
import _ from 'lodash';
|
|
|
|
|
2022-07-19 07:58:56 +00:00
|
|
|
import ReducerRegistry from '../redux/ReducerRegistry';
|
2019-05-24 11:06:05 +00:00
|
|
|
|
|
|
|
import { UPDATE_FLAGS } from './actionTypes';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Default state value for the feature flags.
|
|
|
|
*/
|
|
|
|
const DEFAULT_STATE = {};
|
|
|
|
|
2022-07-19 07:58:56 +00:00
|
|
|
export interface IFlagsState {
|
|
|
|
flags?: Object;
|
|
|
|
}
|
|
|
|
|
2019-05-24 11:06:05 +00:00
|
|
|
/**
|
|
|
|
* Reduces redux actions which handle feature flags.
|
|
|
|
*
|
|
|
|
* @param {State} state - The current redux state.
|
|
|
|
* @param {Action} action - The redux action to reduce.
|
|
|
|
* @param {string} action.type - The type of the redux action to reduce.
|
|
|
|
* @returns {State} The next redux state that is the result of reducing the
|
|
|
|
* specified action.
|
|
|
|
*/
|
2022-09-05 09:05:07 +00:00
|
|
|
ReducerRegistry.register<IFlagsState>('features/base/flags', (state = DEFAULT_STATE, action): IFlagsState => {
|
2019-05-24 11:06:05 +00:00
|
|
|
switch (action.type) {
|
|
|
|
case UPDATE_FLAGS: {
|
|
|
|
const newState = _.merge({}, state, action.flags);
|
|
|
|
|
|
|
|
return _.isEqual(state, newState) ? state : newState;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
});
|