Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // actions.js
- import { getBeers } from '../path/to/file';
- // ...
- export function fetchBeersSuccess(beers) {
- return {
- type: types.FETCH_BEERS_SUCCESS,
- payload: beers,
- };
- }
- export function fetchBeersFailure(error) {
- return {
- type: types.FETCH_BEERS_FAILURE,
- error,
- };
- }
- export function fetchBeers() {
- return (dispatch) => {
- dispatch({
- type: types.FETCH_BEERS,
- });
- const onSuccess = compose(dispatch, fetchBeersSuccess, prop('data'));
- const onFailure = compose(dispatch, fetchBeersFailure);
- return getBeers()
- .then(onSuccess)
- .catch(onFailure);
- };
- }
Add Comment
Please, Sign In to add comment