({
prefix: String,
states: [...String]
}) => ({ entity: String }) => {
...[String]: ReduxAction
}
yarn add -D async-redux-actions redux-actions
async-redux-actions is a small helper that uses redux-actions to create a set of action creators and action types that you can use for all of your app's actions. It helps you by taking an object of actions and returning a set of action creators and actions types.
I like using redux-actions
in conjunction with redux-promise-middleware, but felt icky about writing things like ${userActions.signIn.toString()}/RECEIVED
.
// user.js
import createActions from 'async-redux-actions';
const actions = createActions({
states: ['REQUESTED', 'RECEIVED', 'REJECTED'],
prefix: '💎',
}); // returns an function that is waiting on an entity and an object of actions.
export default actions({ entity: 'user ' })({
PROFILE: promiseApi.getProfile,
});
That will create these action creators and types:
profile.requested()
profile.received()
profile.rejected()
profile()
along side of redux-promise-middleware
, dispatching profile
will kick off
each action according to it's state, just like normal.
'💎/USER/PROFILE/REQUESTED'
,'💎/USER/PROFILE/RECEIVED'
,'💎/USER/PROFILE/REJECTED'
here's a full sample