Skip to content

Instantly share code, notes, and snippets.

@mturley
Last active June 21, 2018 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mturley/4eafb549b5dce99abf6b4726f393ee2d to your computer and use it in GitHub Desktop.
Save mturley/4eafb549b5dce99abf6b4726f393ee2d to your computer and use it in GitHub Desktop.
example of reducer handlers in an object
import {
BLUEPRINTS_FILTER_UPDATE_VALUES,
COMPONENTS_FILTER_UPDATE_VALUES, COMPONENTS_FILTER_ADD_VALUE
} from '../actions/filter';
// const filter = (state = [], action) => {
// switch (action.type) {
// case COMPONENTS_FILTER_ADD_VALUE:
// // ...
// return Object.assign({}, state,
// { components: Object.assign({}, state.components,
// { filterValue: updated })
// });
// case SOME_OTHER_ACTION:
// // ...
// return something;
// default:
// return state;
// }
// };
const handlers = {
[COMPONENTS_FILTER_ADD_VALUE]: (state, action) => {
// ...
return Object.assign({}, state,
{ components: Object.assign({}, state.components,
{ filterValue: updated })
});
},
[SOME_OTHER_ACTION]: (state, action) => {
// ...
// return something;
}
};
const filter = (state = [], action) => {
const handler = handlers[action.type];
if (handler) {
return handler(state, action);
}
return state;
};
export default filter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment