1.0.7 • Published 5 years ago

redux-cut-tools v1.0.7

Weekly downloads
6
License
ISC
Repository
github
Last release
5 years ago

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
 *      }
 *    },
 *  })
 */
1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago