Skip to content

Instantly share code, notes, and snippets.

@SRatna
Created March 22, 2018 11:19
Show Gist options
  • Save SRatna/3b80c210cf047f50484d105ee34efd3d to your computer and use it in GitHub Desktop.
Save SRatna/3b80c210cf047f50484d105ee34efd3d to your computer and use it in GitHub Desktop.
import snakeCase from 'lodash/snakeCase'
/**
* Convert a object with action creators created with
* redux-actions createAction to a object with these
* functions names as action types
*
* "someAction" becomes "SOME_ACTION"
*
* @param {Object} actions Object with action creators
* @return {Object} Object with action types constants
*/
export default (actions) => {
const constants = {}
Object.keys(actions).forEach(action => {
const actionType = actions[action].toString()
const actionConstant = snakeCase(action).toUpperCase()
constants[actionConstant] = actionType
})
return constants
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment