@meadow/redux-api-middleware

3.0.0 • Public • Published

Redux API Middleware

redux-api-middleware provides a middleware function to use as part of the redux dispatch chain. It is intended for use with the Meadow API promise library to provide a middleware to dispatch actions for REQUEST, SUCCESS, and FAILURE.

Installation

npm install @meadow/redux-api-middleware

Usage

Configure store:

import apiMiddleware from '@meadow/redux-api-middleware';
import thunkMiddleware from 'redux-thunk';

const middleware = [thunkMiddleware, apiMiddleware];

const createStoreWithMiddleware = applyMiddleware(...middleware)(createStore);

Action:

import {
  FETCH_ORGANIZATION_REQUEST,
  FETCH_ORGANIZATION_SUCCESS,
  FETCH_ORGANIZATION_FAILURE
} from './constants';
import { CALL_API } from '@meadow/redux-api-middleware';

export function fetchOrganization () {
  return (dispatch, getState) => {
    return dispatch({
      [CALL_API]: {
        types: [
          FETCH_ORGANIZATION_REQUEST,
          FETCH_ORGANIZATION_SUCCESS,
          FETCH_ORGANIZATION_FAILURE
        ],
        promise: Meadow.getOrganization()
      }
    });
  };
}

Package Sidebar

Install

npm i @meadow/redux-api-middleware

Weekly Downloads

0

Version

3.0.0

License

MIT

Last publish

Collaborators

  • jwickens
  • kalli8
  • rickharrison
  • scottagarman
  • harrisonlee
  • fauntleroy
  • meadow-org