|
| 1 | +# Introduction |
| 2 | +[](https://travis-ci.org/reactor-studio/re-create-actions) |
| 3 | +[](#contributors) |
| 4 | + |
| 5 | + |
| 6 | +Reduce boilerplate of your Redux actions by creating [flux-standard-actions](https://github.com/acdlite/flux-standard-action) with a set of utilities this package provides. |
| 7 | + |
| 8 | +## TL;DR |
| 9 | + |
| 10 | +```javascript |
| 11 | +// actions.js |
| 12 | +import { |
| 13 | + createAction, |
| 14 | + createRequestTypes, |
| 15 | + createRequestActions |
| 16 | +} from 're-create-actions'; |
| 17 | + |
| 18 | +// Constans |
| 19 | +const GET_GITHUB_USERS = 'GET_GITHUB_USERS'; |
| 20 | + |
| 21 | +// Create action creator |
| 22 | +export const getGithubUsers = createAction(GET_GITHUB_USERS); |
| 23 | +// Use: dispatch(getGithubUsers()) |
| 24 | + |
| 25 | +// Create network types/constants |
| 26 | +const GET_GITHUB_USERS_RT = createRequestTypes('GET_GITHUB_USERS_RT'); |
| 27 | +// Use: GET_GITHUB_USERS_RT.REQUESTED, GET_GITHUB_USERS_RT.COMPLETED, GET_GITHUB_USERS_RT.FAILED |
| 28 | + |
| 29 | +// Create actions from network types |
| 30 | +const getGithubUsersRT = createRequestActions(GET_GITHUB_USERS_RT); |
| 31 | +// Use: dispatch(getGithubUsersRT.requested()) |
| 32 | + |
| 33 | +``` |
| 34 | + |
| 35 | +# Install |
| 36 | + |
| 37 | +### NPM |
| 38 | +```bash |
| 39 | +$ npm install re-create-actions --save |
| 40 | +``` |
| 41 | + |
| 42 | +### Yarn |
| 43 | +```bash |
| 44 | +$ yarn add re-create-actions |
| 45 | +``` |
| 46 | + |
| 47 | +# Usage |
| 48 | +Every helper will create action that is defined in shape by Flux standard action. We decided to go with Flux standard action because it gives you definition of minimal, common standards that are human-friendly and enable |
| 49 | +us to create assumptions about the shape of our actions. |
| 50 | + |
| 51 | +*NOTE*: You can't disable flux standard action structure at the moment. But there is an [open issue]() for this. |
| 52 | + |
| 53 | +# API |
| 54 | + |
| 55 | +## createAction (type, payloadCreator, metaCreator) |
| 56 | + |
| 57 | +#### type (required) |
| 58 | +Type: `string` |
| 59 | + |
| 60 | +Type for your type property in [action](https://redux.js.org/basics/actions) |
| 61 | + |
| 62 | +#### payloadCreator (optional) |
| 63 | +Type: `function` |
| 64 | + |
| 65 | +Custom payload creator for action payload |
| 66 | + |
| 67 | +#### metaCreator (optional) |
| 68 | +Type: `function` |
| 69 | + |
| 70 | +Custom meta creator for action |
| 71 | + |
| 72 | + |
| 73 | +# createRequestTypes(type) |
| 74 | + |
| 75 | +#### type |
| 76 | +Type: `string` |
| 77 | + |
| 78 | +Type for your request types |
| 79 | + |
| 80 | +## Credits |
| 81 | +Projects was inspired by headaches given from reading bunch of boilerplates during pull request reveiws at [reactor.studio](https://github.com/reactor-studio`). |
| 82 | + |
| 83 | +API for this package was inspired by this awesome projects: |
| 84 | +* [flux-standard-action](https://github.com/acdlite/flux-standard-action) |
| 85 | +* [redux-actions](https://github.com/reduxactions/redux-actions) |
| 86 | + |
| 87 | + |
| 88 | +## Contributors |
| 89 | + |
| 90 | +Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)): |
| 91 | + |
| 92 | +<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section --> |
| 93 | +<!-- prettier-ignore --> |
| 94 | +| [<img src="https://avatars3.githubusercontent.com/u/1723170?v=4" width="100px;"/><br /><sub><b>Vedran Blazenka</b></sub>](https://www.vblazenka.com/)<br />[💻](https://github.com/reactor-studio/re-create-actions/commits?author=wedranb "Code") [📖](https://github.com/reactor-studio/re-create-actions/commits?author=wedranb "Documentation") | [<img src="https://avatars2.githubusercontent.com/u/1530952?v=4" width="100px;"/><br /><sub><b>Dino Trojak</b></sub>](http://reactor.studio)<br />[💻](https://github.com/reactor-studio/re-create-actions/commits?author=dinodsaurus "Code") | |
| 95 | +| :---: | :---: | |
| 96 | +<!-- ALL-CONTRIBUTORS-LIST:END --> |
| 97 | + |
| 98 | +This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome! |
0 commit comments