Skip to content

Instantly share code, notes, and snippets.

@ustun ustun/todoappreducer8.js Secret
Last active Feb 8, 2017

Embed
What would you like to do?
todoappreducer8.js
function reducerFromRecordClass(klass) {
return function todoAppReducer(state=new klass(), action) {
var fn = state[camelcase(action.type)]
if (fn) {
return state[camelcase(action.payload)](action);
} else {
// we don’t recognize the method, return current state.
return state;
}
}
}
todoReducer = reducerFromRecordClass(Todo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.