async-redux-actions
v2.0.1
Published
generate async redux action types and creators
Downloads
4
Readme
Async Redux Action Creators
({
prefix: String,
states: [...String]
}) => ({ entity: String }) => {
...[String]: ReduxAction
}
install
yarn add -D async-redux-actions redux-actions
What
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.
Why
I like using redux-actions
in conjunction with redux-promise-middleware, but felt icky about writing things like ${userActions.signIn.toString()}/RECEIVED
.
How
// 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:
action creators
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.
types
'💎/USER/PROFILE/REQUESTED'
,'💎/USER/PROFILE/RECEIVED'
,'💎/USER/PROFILE/REJECTED'
here's a full sample