All files actions.js

92.86% Statements 13/14
50% Branches 1/2
100% Functions 1/1
92.86% Lines 13/14
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      3x       3x 3x   3x 16x 16x 16x   16x 16x 16x   16x 16x           3x    
import { actionCreator, snakeCaseToCamel } from './utils'
 
export default function actions(prefix, baseActionTypes) {
  Iif (!(baseActionTypes instanceof Array)) {
    throw new Error('Please supply an array of actions as strings as a second argument')
  }
 
  const actionCreators = {}
  const types = {}
 
  for (let i = 0; i < baseActionTypes.length; i += 1) {
    const actionType = baseActionTypes[i]
    const successType = `${prefix}/${actionType}_SUCCESS`
    const failureType = `${prefix}/${actionType}_FAILURE`
 
    types[actionType] = `${prefix}/${actionType}`
    types[`${actionType}_SUCCESS`] = successType
    types[`${actionType}_FAILURE`] = failureType
 
    const camelCaseActionType = snakeCaseToCamel(actionType)
    actionCreators[camelCaseActionType] = actionCreator(
      types[actionType],
      { successType, failureType },
    )
  }
 
  return { ...types, ...actionCreators }
}