3.0.0 • Published 7 years ago

@meadow/redux-api-middleware v3.0.0

Weekly downloads
5
License
MIT
Repository
github
Last release
7 years ago

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()
      }
    });
  };
}
3.0.0

7 years ago

2.0.0

7 years ago

1.1.1

8 years ago

1.1.0

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago