Skip to content

creates actions, constants and reducers for dumb actions

Notifications You must be signed in to change notification settings

mohtasim85/simpleRedux

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simpleRedux

  • reduce boilerplate for Redux reducers with dumb actions
  • create actionCreators, constants and reducers in a single file
  • actionCreator names are derived by camelCasing the CONSTANT_CASE names

example:

import simpleRedux from 'simpleRedux';

const actions = {
  'INCREMENT': ['step'],
  'DECREMENT': ['step']
};

const reducers = {
  increment(state, action) {
    return state + action.step;
  },

  decrement(state, action) {
    return state - action.step;
  }
};

let counter = simpleRedux(actions, reducers, 5);

counter is now equivalent to the following code:

counter = {

  actionCreators:{
    increment(step) {
      type: 'INCREMENT',
      step
    },
    decrement(step) {
      type: 'DECREMENT',
      step
    }
  },

  constants:{
    INCREMENT: 'INCREMENT',
    DECREMENT: 'DECREMENT'
  },

  reducer: function(state = 5, action)
    switch(action.type) {
      case 'INCREMENT':
        return state + action.step;
      case 'DECREMENT':
        return state - action.step;
      default:
        return state;
    }
  }
}

About

creates actions, constants and reducers for dumb actions

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%