Created
August 23, 2016 09:14
-
-
Save tokenvolt/3bf9367586e40196b872266c4593a85d to your computer and use it in GitHub Desktop.
Redux action types generator
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 R from 'ramda' | |
/* | |
Example | |
createAsyncActionType('LOGIN') | |
will return an object | |
{ | |
LOGIN_REQUEST: 'LOGIN_REQUEST', | |
LOGIN_SUCCESS: 'LOGIN_SUCCESS', | |
LOGIN_FAILURE: 'LOGIN_FAILURE' | |
} | |
*/ | |
export const createAsyncActionType = (prefix) => { | |
const obj = {} | |
obj[`${prefix}_REQUEST`] = `${prefix}_REQUEST` | |
obj[`${prefix}_SUCCESS`] = `${prefix}_SUCCESS` | |
obj[`${prefix}_FAILURE`] = `${prefix}_FAILURE` | |
return obj | |
} | |
/* | |
Example | |
createSyncActionType('CHANGE_TAB') | |
will return an object | |
{ | |
CHANGE_TAB: 'CHANGE_TAB' | |
} | |
*/ | |
export const createSyncActionType = (prefix) => { | |
const obj = {} | |
obj[prefix] = prefix | |
return obj | |
} | |
// These functions are for generating a list of types | |
export const createAsyncActions = (...col) => | |
col.reduce((acc, el) => | |
R.merge(acc, createAsyncActionType(el)), {}) | |
export const createSyncActions = (...col) => | |
col.reduce((acc, el) => | |
R.merge(acc, createSyncActionType(el)), {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment