Skip to content

Generate redux reducers from mapping action types to method that handles those actions.

License

Notifications You must be signed in to change notification settings

0xc14m1z/redux-reducer-generator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

redux-reducer-generator

Build Status Coverage Status Maintainability

how to install

$ npm install --save redux-reducer-generator

how to use it

The goal of this package is to shorten and lean the switch statement for redux reducers, replacing it with a map between action types and methods that handles those actions.

import reducer from "redux-reducer-generator"
// or var reducer = require("redux-reducer-generator")

const initialState = {
  loading: false,
  errors: false
}

const SHOW_LOADER = "SHOW_LOADER"
const HIDE_LOADER = "HIDE_LOADER"

const showLoader = (state, action) =>
  ({ ...state, loading: true })

const hideLoader = (state, action) =>
  ({ ...state, loading: false })

const map = {
  [SHOW_LOADER]: showLoader,
  [HIDE_LOADER]: hideLoader
}

const loadingReducer = reducer(initialState, map)

About

Generate redux reducers from mapping action types to method that handles those actions.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published