Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/darmody/redux-action-types-creator
A simple lib help you define redux action type in easy way.
https://github.com/darmody/redux-action-types-creator
react redux redux-actions
Last synced: 14 days ago
JSON representation
A simple lib help you define redux action type in easy way.
- Host: GitHub
- URL: https://github.com/darmody/redux-action-types-creator
- Owner: Darmody
- Created: 2016-10-26T23:52:59.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2017-06-06T02:59:21.000Z (over 7 years ago)
- Last Synced: 2024-12-16T05:27:23.021Z (about 2 months ago)
- Topics: react, redux, redux-actions
- Language: JavaScript
- Homepage:
- Size: 18.6 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# redux-action-types-creator
[![build status][travis-image]][travis-url]
A simple lib help your define `redux action type` in easy way.
## Installation
```
yarn add redux-action-types-creator
```Or
```
npm install redux-action-types-creator --save
```## Usage
```js
import actionTypeCreator, { SYNC, ASYNC } from 'redux-action-types-creator'const actionType = actionTypeCreator('APP')
const TODO_TYPES = actionType({
TODO: {
CREATE: SYNC,
UPDATE: SYNC,
FETCH: ASYNC,
USER: {
FETCH: ASYNC,
DELETE: SYNC,
}
}
})/**
{
TODO: {
CREATE: '@@APP/TODO/CREATE',
UPDATE: '@@APP/TODO/UPDATE',
FETCH: {
START: '@@APP/TODO/FETCH/REQUEST',
SUCCESS: '@@APP/TODO/FETCH/SUCCESS',
FAIL: '@@APP/TODO/FETCH/FAILURE',
ALL: [
'@@APP/TODO/FETCH/REQUEST',
'@@APP/TODO/FETCH/SUCCESS',
'@@APP/TODO/FETCH/FAILURE',
]
},
USER: {
FETCH: {
START: '@@APP/TODO/USER/FETCH/REQUEST',
SUCCESS: '@@APP/TODO/USER/FETCH/SUCCESS',
FAIL: '@@APP/TODO/USER/FETCH/FAILURE',
ALL: [
'@@APP/TODO/USER/FETCH/REQUEST',
'@@APP/TODO/USER/FETCH/SUCCESS',
'@@APP/TODO/USER/FETCH/FAILURE',
]
},
DELETE: '@@APP/TODO/USER/DELETE',
}
}
}*/
// now you can access type like:
console.log(TODO_TYPES.TODO.CREATE) // '@@APP/TODO/CREATE'
console.log(TODO_TYPES.TODO.FETCH.ALL) // access all async types in easy way
/*
[
'@@APP/TODO/FETCH/REQUEST',
'@@APP/TODO/FETCH/SUCCESS',
'@@APP/TODO/FETCH/FAILURE',
]
*/
```**SYNC**: generate a single normal type.
**ASYNC**: generate three types for async operation.You can define your own async types suffix by:
```js
actionTypeCreator('namespace', {
asyncSuffix: [
'START', 'SUCCESS', 'FAIL', // default value is: ['REQUEST', 'SUCCESS', 'FAILURE']
]
})
```[travis-image]: https://img.shields.io/travis/Darmody/redux-action-types-creator/master.svg
[travis-url]: https://travis-ci.org/Darmody/redux-action-types-creator