All files / src/store/reducers handleActions.js

100% Statements 4/4
100% Branches 3/3
100% Functions 2/2
100% Lines 4/4
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29                                        6x 38x 12x   26x        
/**
* Copyright 2018, Plotly, Inc.
* All rights reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
 
/**
 * Creates a reducer based on a handler object.
 * Example:
 * ```
 *  const sequences = handleActions({
 *    [types.SEQUENCES_UPDATE]: calculateSequencesState,
 *  }, []);
 * ```
 *
 * Similar to handleActions from redux-actions or createReduce from redux-act
 */
export default function handleActions(handlers, initialState) {
  return function reducer(state = initialState, {type, payload}) {
    if (handlers.hasOwnProperty(type)) {
      return handlers[type](state, payload);
    } else {
      return state;
    }
  };
}