JSPM

redux-await-middleware

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q32418F
  • License MIT

Await(Promise) middleware for Redux

Package Exports

  • redux-await-middleware

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-await-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 Await(Promise) Middleware

Await(Promise) middleware for Redux.

Installation

npm install --save redux-await-middleware

Then, to enable Redux Await(Promise) Middleware, use applyMiddleware():

import { applyMiddleware, createStore } from 'redux';
import awaitMiddleware from 'redux-await-middleware';
import reducers from './reducers/index';

const createStoreWithMiddleware = applyMiddleware(awaitMiddleware)(createStore);
const store = createStoreWithMiddleware(reducers);

Usage

Create action with promise property:

function getData(params) {
  return {
    type: 'GET_DATA',
    promise: request.get('url'), // Return `promise`.
    otherParams: 'someParam'
  }
}

Then, use resolved data on Reducer:

function someReducer(state = defaultState, action) {
  switch (action.type) {
    case 'GET_DATA':
      return state.concat(action.res.data); // Accessable `res` property.
    default:
      return state;
  }
}

License

MIT