redux-action-reducer-mapper

1.0.2 • Public • Published

A mapper that makes it easy to create reducers based on a set of closures mapped to actions.

Use it instead of a gigantic and highly complex (in terms of cyclomatic code complexity) switch statement:

import mapActionToReducer from 'redux-action-reducer-mapper';

const reducer = mapActionToReducer({
  'default': '',
  'MY_ACTION': (state, action) => action.payload
})

is an equivalent of

const reducer = (state = '', action) => {
  switch(action.type) {
    case 'MY_ACTION':
      return action.payload;
    default:
      return state;
  }
}

This reveals that if no action matched the previous state is returned.

Readme

Keywords

Package Sidebar

Install

npm i redux-action-reducer-mapper

Weekly Downloads

18

Version

1.0.2

License

Apache-2.0

Last publish

Collaborators

  • padcom