Last active
June 21, 2018 23:12
-
-
Save mturley/4eafb549b5dce99abf6b4726f393ee2d to your computer and use it in GitHub Desktop.
example of reducer handlers in an object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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