create-redux-module

2.0.1 • Public • Published

Helper to create redux namespaced action creators & reducers with minimal boilerplate. Easily execute actions and run built-in reducer tests from the console during development, even before creating a UI.

Go from this:

const DECREMENT = 'DECREMENT';
const INCREMENT = 'INCREMENT';
 
function createDecrementAction() {
  return {
    type: DECREMENT
  };
}
 
function createIncrementAction() {
  return {
    type: INCREMENT
  };
}
 
export default (state = 0, action) => {
  switch (action.type) {
    case DECREMENT:
      return state - 1;
    case INCREMENT:
      return state + 1;
    default:
      return state;
  }
};

To this:

import createModule from 'create-redux-module';
 
const schema = {
  decrement: (state, action) => state - action.payload
  , increment: (state, action) => state + action.payload
};
 
export const counter = createModule('counter', schema, 0);

Usage

Changes

v2.0.0

  • Removed Promise object notation. Unnecessary and easily achieved using Redux-Thunk + async functions.
  • Added shorthand to specify actionCreator object properties with an array.
  • Now uses immerjs behind the scenes, reducers can return a new state as before (classic), or mutate a draft state which gets converted to a new state by immerjs.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.1
    1
    • latest

Version History

Package Sidebar

Install

npm i create-redux-module

Weekly Downloads

18

Version

2.0.1

License

MIT

Unpacked Size

182 kB

Total Files

30

Last publish

Collaborators

  • pspaulding