https://github.com/ozankasikci/redux-fast-actions
A module to ease the pain of creating actions constants and action creator functions.
https://github.com/ozankasikci/redux-fast-actions
Last synced: about 1 month ago
JSON representation
A module to ease the pain of creating actions constants and action creator functions.
- Host: GitHub
- URL: https://github.com/ozankasikci/redux-fast-actions
- Owner: ozankasikci
- License: mit
- Created: 2018-01-17T09:04:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-02-21T06:58:47.000Z (over 7 years ago)
- Last Synced: 2025-04-19T09:59:08.842Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 58.6 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://travis-ci.org/ozankasikci/redux-fast-actions)
# Why?
Because declaring action constants and action creator function for each action is a real pain.# One object to rule them all
#### Create an action config object in a file, export the generated types and actions.
```javascript
// actions.js
import fastActions from 'redux-fast-actions';const actionsConfig = {
home: {
fetchFeed: { payload: ['feeds'] },
},
profile: {
uploadImage: { payload: ['imagePath', 'imageName'] }
}
}const fasActions = fastActions(actionsConfig);
export const types = fasActions.types;
export const actions = fasActions.actions;
```
#### Import the file anywhere in your project.
```javascript
const { types, actions } = 'path/to/actions.js';// console.log(types)
{
HOME_FETCH_FEED: 'HOME_FETCH_FEED'
PROFILE_UPLOAD_IMAGE: 'PROFILE_UPLOAD_IMAGE'
}// console.log(actions)
{
home: {
fetchFeed: (feeds) => {
return { type: HOME_FETCH_FEED, payload: { feeds } }
}
},
profile: {
uploadImage: (imagePath, imageName) => {
return { type: PROFILE_UPLOAD_IMAGE, payload: { imagePath, imageName } }
}
}
}// you can dispatch the generated actions like;
dispatch(actions.profile.uploadImage(imagePath, imageName))
```# Installation
```javascript
npm i redux-fast-actions --save
```
or if you prefer yarn:
```javascript
yarn add redux-fast-actions
```