Skip to content

Instantly share code, notes, and snippets.

@ustun
Last active February 8, 2017 21:18
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 ustun/a1b441d54894117e8b172065d14a849a to your computer and use it in GitHub Desktop.
Save ustun/a1b441d54894117e8b172065d14a849a to your computer and use it in GitHub Desktop.
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