JSPM

redux-await-middleware

1.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q38834F
  • 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.

Await middleware supprorts FSA actions.

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 plain action function:

function getData(params) {
  return {
    type: 'GET_DATA',
    payload: request.get('http://some_api'), // return Promise.
  }
}

or use redux-actions:

var getData = createAction('GET_DATA', request.get('http://some_api'));

Then, use resolved data on Reducer:

function someReducer(state = defaultState, action) {
  switch (action.type) {
    case 'GET_DATA':
      // can access result using payload property.
      return state.concat(action.payload);
    default:
      return state;
  }
}

License

MIT