Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
@doodle/ab-connector / src / state / reducer / abReducer.js
Size: Mime:
import { ActionTypes } from '../actions/abActions';
import { initialState } from '../index';

export const reducer = (state = initialState, action) => {
  switch (action.type) {
    case ActionTypes.CHOOSE_EXPERIMENT: {
      const { name, ...rest } = action.payload;
      return {
        ...state,
        experiments: {
          ...state.experiments,
          [name]: { ...rest },
        },
      };
    }
    case ActionTypes.VARIANT_MOUNTED: {
      const { experimentName, experimentVariant } = action.payload;
      return {
        ...state,
        mountedExperiments: {
          ...state.experiments,
          [experimentName]: experimentVariant,
        },
      };
    }
    case ActionTypes.VARIANT_DISMOUNTED: {
      // eslint-disable-next-line no-unused-vars
      const { [action.payload]: _, ...rest } = state.mountedExperiments;
      return {
        ...state,
        mountedExperiments: {
          ...rest,
        },
      };
    }
    default:
      return state;
  }
};

/**
 * Creates a reducer that can be used with [`combineReducer`](http://redux.js.org/docs/api/combineReducers.html)
 * @param {Object} options Reducer options
 * @param {string} options.domain For mounting this reducer under a different key in redux. Default: `ab`.
 *
 * @example
 * // reducer.js
 * import { createReducer as createAbReducer } from '@doodle/ab-connector';
 * import { combineReducers } from 'redux';
 *
 * export default combineReducers({
 *   ...createAbReducer(), // providing the reducer under the `domain` key
 * })
 */
export const createReducer = (options = {}) => ({
  [options.domain || 'ab']: reducer,
});