Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add promise middleware #38

Closed
yamadapc opened this issue Sep 21, 2016 · 1 comment
Closed

Add promise middleware #38

yamadapc opened this issue Sep 21, 2016 · 1 comment
Assignees

Comments

@yamadapc
Copy link
Contributor

yamadapc commented Sep 21, 2016

Promise middleware is a redux middleware that allows:

function myAction() {
  return {
    payload: {
      promise: fetch('/api/something').then(res => res.json()),
    },
    type: 'SOMETHING',
  };
}

Instead of:

function myAction() {
  return ({ dispatch }) => {
    dispatch({ type: 'SOMETHING_START' });
    fetch('/api/something').then(res => res.json()).then(
      (json) => dispatch({ type: 'SOMETHING_SUCCESS', payload: json }),
      (err) => dispatch({ type: 'SOMETHING_ERROR', payload: err })
    );
  };
}
@yamadapc
Copy link
Contributor Author

It allows DRYer promise based code.

@yamadapc yamadapc self-assigned this Sep 23, 2016
yamadapc added a commit that referenced this issue Sep 26, 2016
Adds optional `redux-logger` support and the promise-middleware.

This closes #38.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant