Guest User

Untitled

a guest
Feb 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. // actions.js
  2.  
  3. import { getBeers } from '../path/to/file';
  4. // ...
  5.  
  6. export function fetchBeersSuccess(beers) {
  7. return {
  8. type: types.FETCH_BEERS_SUCCESS,
  9. payload: beers,
  10. };
  11. }
  12.  
  13. export function fetchBeersFailure(error) {
  14. return {
  15. type: types.FETCH_BEERS_FAILURE,
  16. error,
  17. };
  18. }
  19.  
  20. export function fetchBeers() {
  21. return (dispatch) => {
  22. dispatch({
  23. type: types.FETCH_BEERS,
  24. });
  25.  
  26. const onSuccess = compose(dispatch, fetchBeersSuccess, prop('data'));
  27. const onFailure = compose(dispatch, fetchBeersFailure);
  28.  
  29. return getBeers()
  30. .then(onSuccess)
  31. .catch(onFailure);
  32. };
  33. }
Add Comment
Please, Sign In to add comment