0.2.0 • Published 4 years ago

@tracktl/redux-promise-middleware v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
4 years ago

Redux Promise Middleware

Conventional Commits

Install

npm install --save @tracktl/redux-promise-middleware

or

yarn add @tracktl/redux-promise-middleware

Usage

Create promise implementations:

const API = Symbol('API');

const implementations = new Map([
  [
    API,
    action => {
      if (process.env.NODE_ENV !== 'production') {
        if (typeof action.endpoint !== 'string') {
          throw new Error('Expected endpoint to be a string.');
        }
      }

      return fetch(action.endpoint);
    },
  ]
]);

Add it as a middleware:

import { createStore, applyMiddleware } from 'redux';
import createPromiseMiddleware from '@tracktl/redux-promise-middleware';

const store = createStore(
  reducer,
  applyMiddleware(
    createPromiseMiddleware(implementations)
  )
)

Dispatch an action

store.dispatch({
  promise: API,
  endpoint: '/movies'
  types: ['movies/get:fetching', 'movies/get:success', 'movies/get:fail'],
  // optional metas
  metas: [null, null, null],
});

Local Development

Below is a list of commands you will probably find useful.

npm start or yarn start

Runs the project in development/watch mode.

npm run build or yarn build

Bundles the package to the dist folder. The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

npm test or yarn test

Runs the test watcher (Jest) in an interactive mode. By default, runs tests related to files changed since the last commit.

0.2.0

4 years ago

0.2.0-beta.2

4 years ago

0.2.0-beta.1

4 years ago

0.1.3

6 years ago

0.1.2

6 years ago

0.1.1

6 years ago

0.1.0

6 years ago