The helper for Redux action types constants.
$ npm install kaizenplatform/kaizen-redux-action-types --save
import Types, { async } from 'kaizen-redux-action-types';
First, define action types constants:
// actions/actionTypes.js
import Types, { async } from 'kaizen-redux-action-types';
const types = new Types(
'SORT',
async('FETCH_USER'),
);
export default types;
Then, use get()
to get the defined constants:
// actions/user.js
import types from './actionTypes';
export function request() {
return {
type: types.get('FETCH_USER_REQUEST'),
};
}
export function success(response) {
return {
type: types.get('FETCH_USER_SUCCESS'),
payload: {
response: response.data,
},
};
}
export function error(errors) {
return {
type: types.get('FETCH_USER_FAILURE'),
payload: {
errors,
},
error: true,
};
}
const types = new Types(
'SORT',
async('FETCH_USER'),
);
The shortcut to define async action types. It returns three types with suffix.
${type}_REQUEST
${type}_SUCCESS
${type}_FAILURE
types.get('SORT'); // returns `SORT`
types.get('FETCH_USER_SUCCESS'); // returns `FETCH_USER_SUCCESS`
types.get('UNDEFINED_ACTION'); // An exception is thrown.
$ npm run build
$ npm test
To run test on every file change:
$ npm run test:watch
$ npm run lint
kaizen-redux-action-types is inspired by https://github.com/ripeworks/redux-action-types