redux-promise-middleware
Advanced tools
Comparing version 2.3.3 to 2.4.0
@@ -16,2 +16,3 @@ 'use strict'; | ||
var defaultTypes = ['PENDING', 'FULFILLED', 'REJECTED']; | ||
var IS_ERROR = true; | ||
@@ -50,14 +51,11 @@ function promiseMiddleware() { | ||
type: type + '_' + PENDING | ||
}, !!data ? { payload: data } : {}, !!meta ? { meta: meta } : {})); | ||
}, !data ? {} : { payload: data }, !meta ? {} : { meta: meta })); | ||
var isAction = function isAction(resolved) { | ||
return resolved && (resolved.meta || resolved.payload); | ||
}; | ||
var isThunk = function isThunk(resolved) { | ||
return typeof resolved === 'function'; | ||
}; | ||
var getResolveAction = function getResolveAction(isError) { | ||
var getPartialAction = function getPartialAction(isError) { | ||
return _extends({ | ||
type: type + '_' + (isError ? REJECTED : FULFILLED) | ||
}, !!meta ? { meta: meta } : {}, !!isError ? { error: true } : {}); | ||
}, !meta ? {} : { meta: meta }, !isError ? {} : { error: true }); | ||
}; | ||
@@ -68,18 +66,23 @@ | ||
* 1. a thunk, bound to a resolved/rejected object containing ?meta and type | ||
* 2. the resolved/rejected object, if it looks like an action, merged into action | ||
* 3. a resolve/rejected action with the resolve/rejected object as a payload | ||
* 2. a resolve/rejected action with the resolve/rejected object as a payload | ||
*/ | ||
action.payload.promise = promise.then(function () { | ||
promise.then(function () { | ||
var resolved = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var resolveAction = getResolveAction(); | ||
return dispatch(isThunk(resolved) ? resolved.bind(null, resolveAction) : _extends({}, resolveAction, isAction(resolved) ? resolved : _extends({}, !!resolved && { payload: resolved }))); | ||
var resolveAction = getPartialAction(); | ||
dispatch(isThunk(resolved) ? resolved.bind(null, resolveAction) : _extends({}, resolveAction, !resolved ? {} : { payload: resolved })); | ||
}, function () { | ||
var rejected = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var resolveAction = getResolveAction(true); | ||
return dispatch(isThunk(rejected) ? rejected.bind(null, resolveAction) : _extends({}, resolveAction, isAction(rejected) ? rejected : _extends({}, !!rejected && { payload: rejected }))); | ||
}); | ||
var rejectedAction = getPartialAction(IS_ERROR); | ||
dispatch(isThunk(rejected) ? rejected.bind(null, rejectedAction) : _extends({}, rejectedAction, !rejected ? {} : { payload: rejected })); | ||
})['catch'](function (error) { | ||
return( | ||
// log out any errors thrown as a result of the dispatch in this promise | ||
console.error(error) | ||
); | ||
} // eslint-disable-line | ||
); | ||
return action; | ||
return promise; | ||
}; | ||
@@ -86,0 +89,0 @@ }; |
{ | ||
"name": "redux-promise-middleware", | ||
"version": "2.3.3", | ||
"version": "2.4.0", | ||
"description": "Redux middleware for handling promises", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"pretest": "`npm bin`/eslint ./src/*.js", | ||
"pretest": "eslint ./src/*.js", | ||
"test": "mocha --compilers js:babel/register --reporter spec test/*.js", | ||
@@ -34,2 +34,3 @@ "prepublish": "npm test && make js" | ||
"chai": "^3.4.0", | ||
"escope": "^3.3.0", | ||
"eslint": "^0.24.1", | ||
@@ -40,4 +41,4 @@ "eslint-config-airbnb": "0.0.6", | ||
"redux": "^3.0.4", | ||
"redux-mock-store": "0.0.2", | ||
"sinon": "^1.17.2", | ||
"redux-mock-store": "^1.0.2", | ||
"sinon": "^1.17.3", | ||
"sinon-chai": "^2.8.0" | ||
@@ -47,4 +48,3 @@ }, | ||
"redux": "^2.0.0 || ^3.0.0" | ||
}, | ||
"dependencies": {} | ||
} | ||
} |
# Redux Promise Middleware | ||
[![npm version](https://img.shields.io/npm/v/redux-promise-middleware.svg?style=flat)](https://www.npmjs.com/package/redux-promise-middleware) [![Build Status](https://travis-ci.org/pburtchaell/redux-promise-middleware.svg)](https://travis-ci.org/pburtchaell/redux-promise-middleware) [![Coverage Status](https://coveralls.io/repos/pburtchaell/redux-promise-middleware/badge.svg?branch=master&service=github)](https://coveralls.io/github/pburtchaell/redux-promise-middleware?branch=master) [![npm downloads](https://img.shields.io/npm/dm/redux-promise-middleware.svg?style=flat)](https://www.npmjs.com/package/redux-promise-middleware) | ||
[![npm version](https://img.shields.io/npm/v/redux-promise-middleware.svg?style=flat)](https://www.npmjs.com/package/redux-promise-middleware) [![Build Status](https://travis-ci.org/pburtchaell/redux-promise-middleware.svg)](https://travis-ci.org/pburtchaell/redux-promise-middleware) [![npm downloads](https://img.shields.io/npm/dm/redux-promise-middleware.svg?style=flat)](https://www.npmjs.com/package/redux-promise-middleware) | ||
@@ -38,3 +38,3 @@ # Getting Started | ||
The middleware returns a [FSA compliant](https://github.com/acdlite/flux-standard-action) action for both rejected and resolved/fulfilled promises. In the case of a rejected promise, an `error` is returned. You can access the promise of the action with `payload.promise`. This is useful for chaining actions together or using `async...await` within an action creator. | ||
The middleware returns a [FSA compliant](https://github.com/acdlite/flux-standard-action) action for both rejected and resolved/fulfilled promises. In the case of a rejected promise, an `error` is returned. | ||
@@ -60,3 +60,3 @@ ## What is the difference between this and other promise middleware? | ||
promise: Promise.resolve({ | ||
type: 'SECOND_ACTION_TYPE' | ||
type: 'SECEOND_ACTION_TYPE' | ||
payload: ... | ||
@@ -74,3 +74,3 @@ }) | ||
payload: { | ||
promise: Promise.resolve((action, dispatch, getState) => { | ||
promise: Promise.resolve((dispatch, getState) => { | ||
dispatch({ type: 'SECEOND_ACTION_TYPE', payload: ... }) | ||
@@ -83,4 +83,2 @@ dispatch(someActionCreator()) | ||
Note that this behavior uses thunks, so you will need to include [thunk middleware](https://github.com/gaearon/redux-thunk) in your middleware stack. | ||
## Type suffix configuration | ||
@@ -87,0 +85,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
35908
32
793
12
111
2
3