Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

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.

License

Notifications You must be signed in to change notification settings

pspaulding/create-redux-module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This library is no longer maintained. If you want to use redux, I'd recommend https://redux-toolkit.js.org/

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.

About

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.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published