Created
March 22, 2018 11:19
-
-
Save SRatna/3b80c210cf047f50484d105ee34efd3d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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