Skip to content

Instantly share code, notes, and snippets.

@jrgcubano
Forked from chris-burgin/store.js
Created March 6, 2018 11:33
Show Gist options
  • Save jrgcubano/d60094612cbb0f08cbae245612536cb8 to your computer and use it in GitHub Desktop.
Save jrgcubano/d60094612cbb0f08cbae245612536cb8 to your computer and use it in GitHub Desktop.
Object Literal Redux Store Reducer
// ****************
// Reducer Imports
// ****************
import {
// users
DELETEUSER,
UPDATEUSER,
ADDUSER,
ADDUSERS
} from "./reducers/index.js"
// ****************
// Switch Logic
// ****************
const reducerSwitch = {
// users
"ADDUSER": ADDUSER,
"ADDUSERS": ADDUSERS,
"DELETEUSER": DELETEUSER,
"UPDATEUSER": UPDATEUSER,
}
// ****************
// Reducer Switch
// ****************
const AppReducers = (state, action) =>
reducerSwitch[action.type](state, action) // execute the reducer
@jrgcubano
Copy link
Author

// ****************
// Reducer Switch
// ****************
const AppReducers = (state, action) =>
reducerSwitch.hasOwnProperty(action.type)
? reducerSwitch[action.type](state, action)
: state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment