A collection of tools for quickly generating redux boilerplate code.
$ npm install @twcn/redux-tools --save
or
$ yarn add @twcn/redux-tools
import { createActionTypes, createActions, createReducer } from '@twcn/redux-tools';
const LOGIN = createActionTypes('LOGIN');
console.log(LOGIN);
// {
// REQUEST: 'LOGIN_REQUEST',
// SUCCESS: 'LOGIN_SUCCESS',
// FAILURE: 'LOGIN_FAILURE'
// }
const login = createActions(LOGIN);
console.log(login);
// {
// request: (payload) => ({ type: 'LOGIN_REQUEST', payload }),
// success: (payload) => ({ type: 'LOGIN_SUCCESS', payload }),
// failure: (payload) => ({ type: 'LOGIN_FAILURE', payload })
// }
const loginReducer = createReducer({ isLogin: false }, {
[LOGIN.SUCCESS]: (state, action) => ({
...state,
...action.payload,
isLogin: true
})
});
You can click here to contribute your fantastic ideas.