redux-promise-middleware
Advanced tools
Comparing version 3.3.2 to 4.0.0
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
@@ -9,2 +13,4 @@ | ||
exports.default = promiseMiddleware; | ||
var _isPromise = require('./isPromise'); | ||
@@ -23,3 +29,3 @@ | ||
*/ | ||
module.exports = function promiseMiddleware() { | ||
function promiseMiddleware() { | ||
var config = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -50,10 +56,8 @@ | ||
var _ref = (meta || {}).promiseTypeSuffixes || promiseTypeSuffixes; | ||
var _promiseTypeSuffixes = _slicedToArray(promiseTypeSuffixes, 3); | ||
var _ref2 = _slicedToArray(_ref, 3); | ||
var PENDING = _promiseTypeSuffixes[0]; | ||
var FULFILLED = _promiseTypeSuffixes[1]; | ||
var REJECTED = _promiseTypeSuffixes[2]; | ||
var PENDING = _ref2[0]; | ||
var FULFILLED = _ref2[1]; | ||
var REJECTED = _ref2[2]; | ||
/** | ||
@@ -106,19 +110,12 @@ * @function getAction | ||
* @description Dispatch the rejected action and return | ||
* an error object. The error object should contain the | ||
* reason and the dispatched action. | ||
* an error object. The error object is the original error | ||
* that was thrown. The user of the library is responsible for | ||
* best practices in ensure that they are throwing an Error object. | ||
* @params reason The reason the promise was rejected | ||
* @returns {object} | ||
*/ | ||
var handleReject = function handleReject() { | ||
var reason = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; | ||
var handleReject = function handleReject(reason) { | ||
var rejectedAction = getAction(reason, true); | ||
dispatch(rejectedAction); | ||
var error = reason instanceof Error ? reason : new Error(); | ||
error.reason = reason; | ||
error.action = rejectedAction; | ||
throw error; | ||
throw reason; | ||
}; | ||
@@ -176,2 +173,2 @@ | ||
}; | ||
}; | ||
} |
@@ -59,2 +59,6 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
@@ -66,2 +70,4 @@ | ||
exports.default = promiseMiddleware; | ||
var _isPromise = __webpack_require__(1); | ||
@@ -80,3 +86,3 @@ | ||
*/ | ||
module.exports = function promiseMiddleware() { | ||
function promiseMiddleware() { | ||
var config = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
@@ -107,10 +113,8 @@ | ||
var _ref = (meta || {}).promiseTypeSuffixes || promiseTypeSuffixes; | ||
var _promiseTypeSuffixes = _slicedToArray(promiseTypeSuffixes, 3); | ||
var _ref2 = _slicedToArray(_ref, 3); | ||
var PENDING = _promiseTypeSuffixes[0]; | ||
var FULFILLED = _promiseTypeSuffixes[1]; | ||
var REJECTED = _promiseTypeSuffixes[2]; | ||
var PENDING = _ref2[0]; | ||
var FULFILLED = _ref2[1]; | ||
var REJECTED = _ref2[2]; | ||
/** | ||
@@ -163,19 +167,12 @@ * @function getAction | ||
* @description Dispatch the rejected action and return | ||
* an error object. The error object should contain the | ||
* reason and the dispatched action. | ||
* an error object. The error object is the original error | ||
* that was thrown. The user of the library is responsible for | ||
* best practices in ensure that they are throwing an Error object. | ||
* @params reason The reason the promise was rejected | ||
* @returns {object} | ||
*/ | ||
var handleReject = function handleReject() { | ||
var reason = arguments.length <= 0 || arguments[0] === undefined ? null : arguments[0]; | ||
var handleReject = function handleReject(reason) { | ||
var rejectedAction = getAction(reason, true); | ||
dispatch(rejectedAction); | ||
var error = reason instanceof Error ? reason : new Error(); | ||
error.reason = reason; | ||
error.action = rejectedAction; | ||
throw error; | ||
throw reason; | ||
}; | ||
@@ -233,3 +230,3 @@ | ||
}; | ||
}; | ||
} | ||
@@ -236,0 +233,0 @@ /***/ }, |
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ReduxPromiseMiddleware=e():t.ReduxPromiseMiddleware=e()}(this,function(){return function(t){function e(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return t[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function o(t){return t&&t.__esModule?t:{"default":t}}var n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},u=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t},i=function(){function t(t,e){var r=[],o=!0,n=!1,u=void 0;try{for(var i,a=t[Symbol.iterator]();!(o=(i=a.next()).done)&&(r.push(i.value),!e||r.length!==e);o=!0);}catch(f){n=!0,u=f}finally{try{!o&&a["return"]&&a["return"]()}finally{if(n)throw u}}return r}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),a=r(1),f=o(a),l=["PENDING","FULFILLED","REJECTED"];t.exports=function(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.promiseTypeSuffixes||l;return function(t){var r=t.dispatch;return function(t){return function(o){if(!o.payload)return t(o);if(!(0,f["default"])(o.payload)&&!(0,f["default"])(o.payload.promise))return t(o);var a=o.type,l=o.payload,c=o.meta,y=(c||{}).promiseTypeSuffixes||e,p=i(y,3),d=p[0],s=p[1],m=p[2],v=function(t,e){return u({type:a+"_"+(e?m:s)},t?{payload:t}:{},c?{meta:c}:{},e?{error:!0}:{})},b=void 0,h=void 0;(0,f["default"])(o.payload)||"object"!==n(o.payload)?(b=l,h=null):(b=l.promise,h=l.data),t(u({type:a+"_"+d},h?{payload:h}:{},c?{meta:c}:{}));var x=function(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0],e=v(t,!0);r(e);var o=t instanceof Error?t:new Error;throw o.reason=t,o.action=e,o},S=function(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0],e=v(t,!1);return r(e),{value:t,action:e}};return b.then(S,x)}}}}},function(t,e){"use strict";function r(t){return null!==t&&"object"===("undefined"==typeof t?"undefined":o(t))&&(t&&"function"==typeof t.then)}Object.defineProperty(e,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t};e["default"]=r}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ReduxPromiseMiddleware=e():t.ReduxPromiseMiddleware=e()}(this,function(){return function(t){function e(o){if(r[o])return r[o].exports;var n=r[o]={exports:{},id:o,loaded:!1};return t[o].call(n.exports,n,n.exports,e),n.loaded=!0,n.exports}var r={};return e.m=t,e.c=r,e.p="",e(0)}([function(t,e,r){"use strict";function o(t){return t&&t.__esModule?t:{"default":t}}function n(){var t=arguments.length<=0||void 0===arguments[0]?{}:arguments[0],e=t.promiseTypeSuffixes||c;return function(t){var r=t.dispatch;return function(t){return function(o){if(!o.payload)return t(o);if(!(0,l["default"])(o.payload)&&!(0,l["default"])(o.payload.promise))return t(o);var n=o.type,f=o.payload,c=o.meta,y=a(e,3),d=y[0],p=y[1],s=y[2],m=function(t,e){return i({type:n+"_"+(e?s:p)},t?{payload:t}:{},c?{meta:c}:{},e?{error:!0}:{})},v=void 0,b=void 0;(0,l["default"])(o.payload)||"object"!==u(o.payload)?(v=f,b=null):(v=f.promise,b=f.data),t(i({type:n+"_"+d},b?{payload:b}:{},c?{meta:c}:{}));var h=function(t){var e=m(t,!0);throw r(e),t},x=function(){var t=arguments.length<=0||void 0===arguments[0]?null:arguments[0],e=m(t,!1);return r(e),{value:t,action:e}};return v.then(x,h)}}}}Object.defineProperty(e,"__esModule",{value:!0});var u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t},i=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t},a=function(){function t(t,e){var r=[],o=!0,n=!1,u=void 0;try{for(var i,a=t[Symbol.iterator]();!(o=(i=a.next()).done)&&(r.push(i.value),!e||r.length!==e);o=!0);}catch(f){n=!0,u=f}finally{try{!o&&a["return"]&&a["return"]()}finally{if(n)throw u}}return r}return function(e,r){if(Array.isArray(e))return e;if(Symbol.iterator in Object(e))return t(e,r);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}();e["default"]=n;var f=r(1),l=o(f),c=["PENDING","FULFILLED","REJECTED"]},function(t,e){"use strict";function r(t){return null!==t&&"object"===("undefined"==typeof t?"undefined":o(t))?t&&"function"==typeof t.then:!1}Object.defineProperty(e,"__esModule",{value:!0});var o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol?"symbol":typeof t};e["default"]=r}])}); |
{ | ||
"name": "redux-promise-middleware", | ||
"version": "3.3.2", | ||
"version": "4.0.0", | ||
"description": "Redux middleware for handling promises and optimistic updates", | ||
@@ -10,2 +10,4 @@ "main": "dist/index.js", | ||
"test": "make test_coverage", | ||
"prelocal-test": "npm run lint", | ||
"local-test": "make test", | ||
"build": "npm run build:commonjs & npm run build:umd & npm run build:umd:min", | ||
@@ -70,3 +72,3 @@ "build:commonjs": "`npm bin`/babel src -d dist", | ||
"redux": "^3.0.4", | ||
"redux-mock-store": "0.0.2", | ||
"redux-mock-store": "1.0.3", | ||
"redux-thunk": "^2.0.1", | ||
@@ -73,0 +75,0 @@ "sinon": "^1.17.2", |
@@ -1,3 +0,41 @@ | ||
# 2.0.0 to 3.0.0 | ||
# 3.x to 4.0.0 | ||
This release introduces changes to error handling. | ||
Previously, the parameter of the rejected promise callback was both the dispatched action and an error object. The middleware also *always* constructed a new error object, which caused unexpected mutation and circular references. | ||
**Now, the parameter of the rejected promise callback is the value of `reject`.** The middleware does not construct a new error; it is your responsibility to make sure the promise is rejected with an Error object. | ||
```js | ||
// before | ||
const bar = () => ({ | ||
type: 'FOO', | ||
payload: new Promise(() => { | ||
reject('foo'); | ||
}) | ||
});.then(() => null, ({ reason, action }) => { | ||
console.log(action.type): // => 'FOO' | ||
console.log(reason.message); // => 'foo' | ||
}); | ||
// after | ||
const bar = () => ({ | ||
type: 'FOO', | ||
payload: new Promise(() => { | ||
/** | ||
* Make sure the promise is rejected with an error. You | ||
* can also use `reject(new Error('foo'));`. It's a best | ||
* practice to reject a promise with an Error object. | ||
*/ | ||
throw new Error('foo'); | ||
}) | ||
});.then(() => null, error => { | ||
console.log(error instanceof Error); // => true | ||
console.log(error.message); // => 'foo' | ||
}); | ||
``` | ||
# 2.x to 3.0.0 | ||
This release introduces some major changes to the functionality of the middleware: | ||
@@ -7,3 +45,3 @@ | ||
``` js | ||
```js | ||
// before | ||
@@ -10,0 +48,0 @@ const foo = () => ({ |
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
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
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
276405
77
5924
0
23
49
1