Skip to content

Instantly share code, notes, and snippets.

@jamesplease
Last active February 8, 2017 21:36
Show Gist options
  • Save jamesplease/92891e001bcf1be442879ba8ef58cbb0 to your computer and use it in GitHub Desktop.
Save jamesplease/92891e001bcf1be442879ba8ef58cbb0 to your computer and use it in GitHub Desktop.
import simpleResource from 'redux-simple-resource';
const books = simpleResource('book', {
// Maybe not necessary
pluralForm: 'books',
actions: {
// Pass `false` to turn it off. Default is `true`
create: false,
// Pass an object to configure the xhr request.
readOne: {
xhrOptions: {},
// Pass a function to transform the data
transform(data) {}
},
// Pass a function to override the action creator. It can
// be a thunk, or not.
readMany() {
return () => {
}
}
}
// Register custom reducer handlers.
customActionHandlers: {
[books.customActionTypes.CUSTOM_ACTION](state, action) {
return {...state, {}};
}
},
// Override built-in reducers. Errors if a reducer type doesn't exist
// at initialization. Run `defaultHandler()` to get the output of the
// built-in transform. Or, ignore it and provide your own behavior.
builtInActionHandlers: {
[books.actionTypes.CREATE_SUCCESS](state, action, defaultHandler) {
// var state = builtInTransform();
return {
...state,
hello
};
}
}
});
export default books;
export const actionCreators = books.actionCreators;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment