🚀 Socket Launch Week Day 5:Introducing Repository Access Permissions and Custom Roles.Learn more
Sign In

redux-promise-es

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-promise-es

FSA-compliant promise middleware for Redux without lodash.

latest
Source
npmnpm
Version
0.6.3
Version published
Maintainers
1
Created
Source

redux-promise-es

npm install --save redux-promise-es

Usage

import promiseMiddleware from 'redux-promise-es';
import { createPromiseMiddleware } from 'redux-promise-es';

dispatch(
  new Promise(resolve => {
    resolve({
      type: 'ACTION_TYPE',
      payload: new Promise()
    });
  })
);
//or
dispatch({
  type: 'ACTION_TYPE',
  payload: new Promise()
});

The default export is a middleware function. If it receives a promise, it will dispatch the resolved value of the promise. It will not dispatch anything if the promise rejects.

If it receives an Flux Standard Action whose payload is a promise, it will either

  • when register middleware use createPromiseMiddleware(true), immediately dispatch a copy of the action.
  • dispatch a copy of the action with the resolved value of the promise, and set status to success.
  • dispatch a copy of the action with the rejected value of the promise, and set status to error.

The middleware returns a promise to the caller so that it can wait for the operation to finish before continuing. This is especially useful for server-side rendering. If you find that a promise is not being returned, ensure that all middleware before it in the chain is also returning its next() call to the caller.

Different from redux-promise

  • use lodash-es, build size package reduce 60kb (redux-promise will package the entire lodash).
  • when register middleware use createPromiseMiddleware(true), immediately dispatch a copy of the action ({ type, loading: true }).

Keywords

redux

FAQs

Package last updated on 06 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts