https://github.com/dielduarte/redux-actiontypes-namespace
add name spaces to your global actionTypes in an easy way
https://github.com/dielduarte/redux-actiontypes-namespace
Last synced: 10 months ago
JSON representation
add name spaces to your global actionTypes in an easy way
- Host: GitHub
- URL: https://github.com/dielduarte/redux-actiontypes-namespace
- Owner: dielduarte
- Created: 2018-05-18T17:57:32.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2022-12-09T08:37:52.000Z (about 3 years ago)
- Last Synced: 2024-10-12T06:25:06.990Z (over 1 year ago)
- Language: JavaScript
- Size: 385 KB
- Stars: 4
- Watchers: 2
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# redux-actiontypes-namespace
Add nameSpaces to your global actionTypes in an easy way
## How to use
First install
```js
yarn add redux-actiontypes-namespace
```
import `createActionTypes` function, example:
```js
import createActionTypes from 'redux-actiontypes-namespace';
const actionTypes = [
{
nameSpace: 'nameSpace1',
types: [
'TYPE_NAME',
'ANOTHER_TYPE'
]
},
{
nameSpace: 'nameSpace2',
types: [
'SECOND_TYPE_NAME',
'SECOND_ANOTHER_TYPE'
]
}
];
export default createActionTypes(actionTypes);
```
now your actionTypes shoud be like:
```
{
TYPE_NAME: 'nameSpace1/TYPE_NAME',
ANOTHER_TYPE: 'nameSpace1/ANOTHER_TYPE',
SECOND_TYPE_NAME: 'nameSpace2/SECOND_TYPE_NAME',
SECOND_ANOTHER_TYPE: 'nameSpace2/SECOND_ANOTHER_TYPE'
}
```
So, now just import your actionTypes and you can use in a normal way.
```
import types from 'where-your-file-was-created';
dispatch({ type: types.TYPE_NAME })
```
or with object destructuring:
```
import { TYPE_NAME } from 'where-your-file-was-created';
dispatch({ type: TYPE_NAME })
```
made with <3