veritus / veritus-web

Frontend
https://deploy-preview-32--announcer-tachometer-25258.netlify.com/
2 stars 0 forks source link

Middleware for dispatching request, success and error actions #64

Open AriHrannar opened 6 years ago

AriHrannar commented 6 years ago

Description

Instead of doing this everytime:

export const fetchSubjectsPromises = () => (dispatch: Dispatch) => {
  dispatch(getSubjectsPromises());

  return apiGetSubjectsPromises().then(
    resp => resp.data && dispatch(getSubjectsPromisesSuccess(resp.data)),
    error => dispatch(getSubjectsPromisesFailure(error.message))
  );
};

its possible to have some middleware that takes in the action types and dispatches them. Is that a good idea? Do we gain anything from doing that?