Skip to content

Instantly share code, notes, and snippets.

@oconn
Created November 18, 2016 16:31
Show Gist options
  • Save oconn/e7b6e2e88998bf88cb98749fc36b5913 to your computer and use it in GitHub Desktop.
Save oconn/e7b6e2e88998bf88cb98749fc36b5913 to your computer and use it in GitHub Desktop.
Request Middleware
export const REQUEST_DELETE_USER = 'REQUEST_DELETE_USER';
export const USER_REMOVE_USER = 'USER_REMOVE_USER';
export const removeUser = (userId) => {
return (dispatch, getState) => {
// The middleware picks up on the following signature
//
// 1. request prop
// 2. request prop is thenable
//
// If the signature is a match then the request store will be updated with
// the request metadata includeing loading status & parsed response headers (pagination support)
dispatch({
type: REQUEST_DELETE_USER,
request: deleteUser(userId, authDAO.getToken(getState())),
onSuccess: () => {
dispatch({
type: USER_REMOVE_USER,
payload: userId
})
}
});
};
};
// ...
const mapStateToProps = (state) => {
return {
tils: tilDao.getTils(state)
};
};
const mapDispatchToProps = (dispatch) => {
return {
actions: bindActionCreators({
getTils
}, dispatch)
};
};
const loadingProps = {
isPaginating: true,
requestName: REQUEST_FETCH_TILS
};
export default compose(
loading(loadingProps),
connect(mapStateToProps, mapDispatchToProps)
)(Til);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment