redux-cut-tools
v1.0.7
Published
more efficient tools about redux
Downloads
1
Readme
redux-cut-tools
more efficient tools about redux
使用说明
npm i redux-cut-tools -S
import { actionMap, reducerMap } from 'redux-cut-tools'
actionMap
/**
*
* @param {Object} actions
*
* key: your custom actionName
* value: action
*
* @returns {Function} mapDispatchToProps
*
* Before
* const mapDispatchToProps = (dispatch) => ({
* login: bindActionCreators(login, dispatch),
* logout: bindActionCreators(logout, dispatch),
* customActionName: bindActionCreators(getVersionInfo, dispatch)
* });
*
* After
* const mapDispatchToProps = actionMap({
* login,
* logout,
* customActionName: getVersionInfo
* })
*/
reducerMap
/**
* reducerMap
*
* @param {Object} initState
* @param {Object} reducerMap
*
* key: action type
* value: callback take state & action as params
*
* @returns {Function} recuder
*
* Before
* const reducer = (state, action) => {
* if(action.type === 'anyway') {
* return {
* ...state,
* payload: action.payload
* }
* }
* if(action.type === 'something') {
* return {
* ...state,
* payload: action.payload
* }
* }
* return state
* }
*
* After
* const reducer = reducerMap(state, {
* 'anyway': (state, action) => {
* return {
* ...state,
* payload: action.payload
* }
* },
* 'something': (state, action) => {
* return {
* ...state,
* payload: action.payload
* }
* },
* })
*/