Created
November 18, 2016 16:31
-
-
Save oconn/e7b6e2e88998bf88cb98749fc36b5913 to your computer and use it in GitHub Desktop.
Request Middleware
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
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 | |
}) | |
} | |
}); | |
}; | |
}; |
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
// ... | |
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