Have ideas to improve npm?Join in the discussion! »

    redux-await-middleware

    1.3.0 • Public • Published

    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

    Install

    npm i redux-await-middleware

    DownloadsWeekly Downloads

    7

    Version

    1.3.0

    License

    MIT

    Last publish

    Collaborators

    • avatar