|
7 | 7 | [](http://commitizen.github.io/cz-cli/) |
8 | 8 | [](https://conventionalcommits.org) |
9 | 9 | [](https://github.com/prettier/prettier) |
10 | | -[](https://github.com/VinSpee/async-redux-actions/blob/master/LICENSE) |
| 10 | +[](https://github.com/VinSpee/async-redux-actions/blob/master/LICENSE) |
| 11 | + |
| 12 | +``` |
| 13 | +({ |
| 14 | + prefix: String, |
| 15 | + states: [...String] |
| 16 | +}) => ({ entity: String }) => { |
| 17 | + ...[String]: ReduxAction |
| 18 | +} |
| 19 | +``` |
| 20 | + |
| 21 | +##install |
| 22 | + |
| 23 | +`yarn add -D async-redux-actions redux-actions` |
| 24 | + |
| 25 | +##What |
| 26 | + |
| 27 | +async-redux-actions is a small helper that uses[redux-actions](https://redux-actions.js.org/) 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. |
| 28 | + |
| 29 | +##Why |
| 30 | + |
| 31 | +I like using`redux-actions` in conjunction with[redux-promise-middleware](https://github.com/pburtchaell/redux-promise-middleware), but felt icky about writing things like`${userActions.signIn.toString()}/RECEIVED`. |
| 32 | + |
| 33 | +##How |
| 34 | + |
| 35 | +```js |
| 36 | +// user.js |
| 37 | + |
| 38 | +importcreateActionsfrom'async-redux-actions'; |
| 39 | + |
| 40 | +constactions=createActions({ |
| 41 | + states: ['REQUESTED','RECEIVED','REJECTED'], |
| 42 | + prefix:'💎', |
| 43 | +});// returns an function that is waiting on an entity and an object of actions. |
| 44 | + |
| 45 | +exportdefaultactions({ entity:'user' })({ |
| 46 | +PROFILE:promiseApi.getProfile, |
| 47 | +}); |
| 48 | +``` |
| 49 | + |
| 50 | +That will create these action creators and types: |
| 51 | + |
| 52 | +###action creators |
| 53 | + |
| 54 | +-`profile.requested()` |
| 55 | +-`profile.received()` |
| 56 | +-`profile.rejected()` |
| 57 | +-`profile()` |
| 58 | + |
| 59 | +along side of`redux-promise-middleware`, dispatching`profile` will kick off |
| 60 | +each action according to it's state, just like normal. |
| 61 | + |
| 62 | +###types |
| 63 | + |
| 64 | +-`'💎/USER/PROFILE/REQUESTED'`, |
| 65 | +-`'💎/USER/PROFILE/RECEIVED'`, |
| 66 | +-`'💎/USER/PROFILE/REJECTED'` |
| 67 | + |
| 68 | +here's a[full sample](https://codesandbox.io/s/r0r7wpjz1o) |