JSPM

  • Created
  • Published
  • Downloads 80928
  • Score
    100M100P100Q162762F
  • License MIT

Redux middleware for handling promises

Package Exports

  • redux-promise-middleware
  • redux-promise-middleware/dist/isPromise

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (redux-promise-middleware) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Redux Promise Middleware

npm version

Getting Started

Install with npm: npm i redux-promise-middleware -S

Usage

First, import the middleware and include it when creating the Redux store:

import promiseMiddleware from 'redux-promise-middleware';

export default createStore(reducers, {}, [
  promiseMiddleware,
]);

To use the middleware, dispatch a promise as the payload of the action and specify a types array.

The pending action is dispatched immediately. The fulfilled action is dispatched only if the promise is resolved, e.g., if it was successful; and the rejected action is dispatched only if the promise is rejected, e.g., if an error occurred.

export function myAsyncActionCreator() {
  return {
    types: [
      'ACTION_PENDING',
      'ACTION_FULFILLED',
      'ACTION_REJECTED'
    ],
    payload: doSomethingAyncAndReturnPromise()
  };
}

The middleware returns a FSA compliant action for both rejected and resolved/fulfilled promises. In the case of a rejected promise, an error is returned.


Licensed MIT. Copyright 2015 Patrick Burtchaell.