Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

redux-promise-middleware

Package Overview
Dependencies
Maintainers
1
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-promise-middleware - npm Package Compare versions

Comparing version 2.2.2 to 2.2.3

22

dist/index.js

@@ -51,6 +51,9 @@ 'use strict';

var isActionOrThunk = function isActionOrThunk(resolved) {
return typeof resolved === 'function' || resolved.meta || resolved.payload;
var isAction = function isAction(resolved) {
return resolved.meta || resolved.payload;
};
var isThunk = function isThunk(resolved) {
return typeof resolved === 'function';
};
/**

@@ -62,11 +65,12 @@ * Return either the fulfilled action object or the rejected

var resolved = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
return dispatch(_extends({
return isThunk(resolved) ? dispatch(resolved) : dispatch(_extends({
type: type + '_' + FULFILLED
}, isActionOrThunk(resolved) ? resolved : _extends({}, resolved && { payload: resolved }, meta && { meta: meta })));
}, function (error) {
return dispatch(_extends({
type: type + '_' + REJECTED,
payload: error,
}, isAction(resolved) ? resolved : _extends({}, resolved && { payload: resolved }, meta && { meta: meta })));
}, function () {
var resolved = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0];
return isThunk(resolved) ? dispatch(resolved) : dispatch(_extends({
type: type + '_' + REJECTED
}, isAction(resolved) ? resolved : _extends({
error: true
}, meta && { meta: meta }));
}, resolved && { payload: resolved }, meta && { meta: meta })));
});

@@ -73,0 +77,0 @@ };

{
"name": "redux-promise-middleware",
"version": "2.2.2",
"version": "2.2.3",
"description": "Redux middleware for handling promises",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -24,3 +24,3 @@ # Redux Promise Middleware

The pending action is dispatched immediately with the original type string and a suffix of `_PENDING`. The fulfilled action is dispatched only if the promise is resolved, e.g., if it was successful; and the rejected action is dispatched only if the promise is rejected, e.g., if an error occurred. The fulfilled and rejected suffixes are `_FULFILLED` and `_REJECTED` respectively.
The pending action is dispatched immediately with the original type string and a suffix of `_PENDING`. The fulfilled action is dispatched only if the promise is resolved, e.g., if it was successful; and the rejected action is dispatched only if the promise is rejected, e.g., if an error occurred. The fulfilled and rejected suffixes are `_FULFILLED` and `_REJECTED` respectively. If necessary, it is possible [to change the value](#type-suffix-configuration) of the type suffixes.

@@ -49,7 +49,39 @@ ```js

## Type Suffix Configuration
## Dispatching actions when promises are resolved
When adding the middleware to your middleware composition layer, you can supply an optional options object. This object accepts an array of suffix strings that can be used instead of the default `['PENDING', 'FULFILLED', 'REJECTED']` with a key of `promiseTypeSuffixes`.
Often times when a promise is resolved, one might want to fire a one or more "callback" actions to respond to the resolved promise. One example is changing the route after a user is successfully signed in.
If you need to do this, you can dispatch a second action:
```js
const actionCreator = () => ({
type: 'FIRST_ACTION_TYPE',
payload: {
promise: Promise.resolve({
type: 'SECEOND_ACTION_TYPE'
payload: ...
})
}
});
```
It is also possible to use a function:
```js
const actionCreator = () => ({
type: 'FIRST_ACTION_TYPE',
payload: {
promise: Promise.resolve((dispatch, getState) => {
dispatch({ type: 'SECEOND_ACTION_TYPE', payload: ... })
dispatch(someActionCreator())
})
}
});
```
## Type suffix configuration
When adding the promise middleware to your middleware stack, you can supply an optional configuration object. This object accepts an array of suffix strings that can be used instead of the default `['PENDING', 'FULFILLED', 'REJECTED']` with a key of `promiseTypeSuffixes`.
```js
applyMiddleware(

@@ -56,0 +88,0 @@ promiseMiddleware({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc