redux-promise-middleware
Advanced tools
Comparing version 2.4.0 to 2.5.0
@@ -15,3 +15,10 @@ 'use strict'; | ||
var defaultTypes = ['PENDING', 'FULFILLED', 'REJECTED']; | ||
var PENDING = 'PENDING'; | ||
exports.PENDING = PENDING; | ||
var FULFILLED = 'FULFILLED'; | ||
exports.FULFILLED = FULFILLED; | ||
var REJECTED = 'REJECTED'; | ||
exports.REJECTED = REJECTED; | ||
var defaultTypes = [PENDING, FULFILLED, REJECTED]; | ||
var IS_ERROR = true; | ||
@@ -41,5 +48,5 @@ | ||
var PENDING = _ref2[0]; | ||
var FULFILLED = _ref2[1]; | ||
var REJECTED = _ref2[2]; | ||
var _PENDING = _ref2[0]; | ||
var _FULFILLED = _ref2[1]; | ||
var _REJECTED = _ref2[2]; | ||
@@ -51,3 +58,3 @@ /** | ||
next(_extends({ | ||
type: type + '_' + PENDING | ||
type: type + '_' + _PENDING | ||
}, !data ? {} : { payload: data }, !meta ? {} : { meta: meta })); | ||
@@ -58,6 +65,7 @@ | ||
}; | ||
var getPartialAction = function getPartialAction(isError) { | ||
return _extends({ | ||
type: type + '_' + (isError ? REJECTED : FULFILLED) | ||
}, !meta ? {} : { meta: meta }, !isError ? {} : { error: true }); | ||
type: type + '_' + (isError ? _REJECTED : _FULFILLED) | ||
}, meta === undefined ? {} : { meta: meta }, !isError ? {} : { error: true }); | ||
}; | ||
@@ -74,3 +82,3 @@ | ||
var resolveAction = getPartialAction(); | ||
dispatch(isThunk(resolved) ? resolved.bind(null, resolveAction) : _extends({}, resolveAction, !resolved ? {} : { payload: resolved })); | ||
dispatch(isThunk(resolved) ? resolved.bind(null, resolveAction) : _extends({}, resolveAction, resolved === undefined ? {} : { payload: resolved })); | ||
}, function () { | ||
@@ -80,3 +88,3 @@ var rejected = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
var rejectedAction = getPartialAction(IS_ERROR); | ||
dispatch(isThunk(rejected) ? rejected.bind(null, rejectedAction) : _extends({}, rejectedAction, !rejected ? {} : { payload: rejected })); | ||
dispatch(isThunk(rejected) ? rejected.bind(null, rejectedAction) : _extends({}, rejectedAction, rejected === undefined ? {} : { payload: rejected })); | ||
})['catch'](function (error) { | ||
@@ -95,3 +103,1 @@ return( | ||
} | ||
module.exports = exports['default']; |
{ | ||
"name": "redux-promise-middleware", | ||
"version": "2.4.0", | ||
"version": "2.5.0", | ||
"description": "Redux middleware for handling promises", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -109,3 +109,8 @@ # Redux Promise Middleware | ||
The default promise status suffix can be imported from this module. | ||
```js | ||
import { PENDING, FULFILLED, REJECTED } from 'redux-promise-middleware' | ||
``` | ||
--- | ||
Licensed MIT. Copyright 2015 Patrick Burtchaell. |
@@ -6,3 +6,3 @@ import chai, { expect } from 'chai'; | ||
import configureStore from 'redux-mock-store'; | ||
import promiseMiddleware from '../src'; | ||
import promiseMiddleware, { PENDING, FULFILLED, REJECTED } from '../src'; | ||
chai.use(sinonChai); | ||
@@ -13,2 +13,8 @@ | ||
it(`exports the default types`, () => { | ||
expect(PENDING).to.eql('PENDING'); | ||
expect(FULFILLED).to.eql('FULFILLED'); | ||
expect(REJECTED).to.eql('REJECTED'); | ||
}); | ||
it('must return a function to handle next', () => { | ||
@@ -146,3 +152,3 @@ expect(nextHandler).to.be.a('function'); | ||
it('returns the new promise object', () => { | ||
it('returns the original promise object from dispatch', () => { | ||
expect(store.dispatch(promiseAction)).to.eql(promiseAction.payload.promise); | ||
@@ -187,6 +193,7 @@ }); | ||
it('works when resolve is null', () => { | ||
it('allows promise to reject resolve null', () => { | ||
rejectingPromiseAction.payload.promise = Promise.reject(null); | ||
rejectedAction = { | ||
type: `${rejectingPromiseAction.type}_REJECTED`, | ||
payload: null, | ||
error: true | ||
@@ -285,6 +292,7 @@ }; | ||
it('works when resolve is null', async () => { | ||
it('allows payload to be null', async () => { | ||
fulfillingPromiseAction.payload.promise = Promise.resolve(null); | ||
fulfillingAction = { | ||
type: `${fulfillingPromiseAction.type}_FULFILLED` | ||
type: `${fulfillingPromiseAction.type}_FULFILLED`, | ||
payload: null | ||
}; | ||
@@ -291,0 +299,0 @@ await store.dispatch(fulfillingPromiseAction); |
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
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
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
36515
805
116
1