@wordpress/redux-routine
Advanced tools
Comparing version 3.0.4 to 3.1.0
/** | ||
* External imports | ||
* External dependencies | ||
*/ | ||
@@ -4,0 +4,0 @@ import { isPlainObject, isString } from 'lodash'; |
@@ -1,3 +0,1 @@ | ||
import _typeof from "@babel/runtime/helpers/esm/typeof"; | ||
/** | ||
@@ -7,3 +5,3 @@ * External dependencies | ||
import { create } from 'rungen'; | ||
import { map, isString } from 'lodash'; | ||
import { map } from 'lodash'; | ||
import isPromise from 'is-promise'; | ||
@@ -14,3 +12,2 @@ /** | ||
import castError from './cast-error'; | ||
import { isActionOfType, isAction } from './is-action'; | ||
@@ -39,7 +36,5 @@ /** | ||
// Async control routine awaits resolution. | ||
routine.then(yieldNext, function (error) { | ||
return yieldError(castError(error)); | ||
}); | ||
routine.then(yieldNext, yieldError); | ||
} else { | ||
next(routine); | ||
yieldNext(routine); | ||
} | ||
@@ -66,3 +61,3 @@ | ||
return rungenRuntime(action, function (result) { | ||
if (_typeof(result) === 'object' && isString(result.type)) { | ||
if (isAction(result)) { | ||
dispatch(result); | ||
@@ -69,0 +64,0 @@ } |
@@ -12,3 +12,3 @@ "use strict"; | ||
/** | ||
* External imports | ||
* External dependencies | ||
*/ | ||
@@ -15,0 +15,0 @@ |
@@ -10,4 +10,2 @@ "use strict"; | ||
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof")); | ||
var _rungen = require("rungen"); | ||
@@ -19,4 +17,2 @@ | ||
var _castError = _interopRequireDefault(require("./cast-error")); | ||
var _isAction = require("./is-action"); | ||
@@ -53,7 +49,5 @@ | ||
// Async control routine awaits resolution. | ||
routine.then(yieldNext, function (error) { | ||
return yieldError((0, _castError.default)(error)); | ||
}); | ||
routine.then(yieldNext, yieldError); | ||
} else { | ||
next(routine); | ||
yieldNext(routine); | ||
} | ||
@@ -80,3 +74,3 @@ | ||
return rungenRuntime(action, function (result) { | ||
if ((0, _typeof2.default)(result) === 'object' && (0, _lodash.isString)(result.type)) { | ||
if ((0, _isAction.isAction)(result)) { | ||
dispatch(result); | ||
@@ -83,0 +77,0 @@ } |
@@ -0,1 +1,10 @@ | ||
## 3.0.4 (Unreleased) | ||
### Bug Fixes | ||
- Fix unhandled promise rejection error caused by returning null from registered generator ([#13314](https://github.com/WordPress/gutenberg/pull/13314)) | ||
- The middleware will no longer attempt to coerce an error to an instance of `Error`, and instead passes through the thrown value directly. This resolves issues where an `Error` would be thrown when the underlying values were not of type `Error` or `string` (e.g. a thrown object) and the message would end up not being useful (e.g. `[Object object]`). | ||
([#13315](https://github.com/WordPress/gutenberg/pull/13315)) | ||
- Fix unintended recursion when invoking sync routine ([#13818](https://github.com/WordPress/gutenberg/pull/13818)) | ||
## 3.0.3 (2018-10-19) | ||
@@ -2,0 +11,0 @@ |
### WordPress - Web publishing software | ||
Copyright 2011-2018 by the contributors | ||
Copyright 2011-2019 by the contributors | ||
@@ -5,0 +5,0 @@ This program is free software; you can redistribute it and/or modify |
{ | ||
"name": "@wordpress/redux-routine", | ||
"version": "3.0.4", | ||
"version": "3.1.0", | ||
"description": "Redux middleware for generator coroutines.", | ||
@@ -16,3 +16,4 @@ "author": "The WordPress Contributors", | ||
"type": "git", | ||
"url": "https://github.com/WordPress/gutenberg.git" | ||
"url": "https://github.com/WordPress/gutenberg.git", | ||
"directory": "packages/redux-routine" | ||
}, | ||
@@ -26,3 +27,3 @@ "bugs": { | ||
"dependencies": { | ||
"@babel/runtime": "^7.0.0", | ||
"@babel/runtime": "^7.3.1", | ||
"is-promise": "^2.1.0", | ||
@@ -34,3 +35,3 @@ "rungen": "^0.3.2" | ||
}, | ||
"gitHead": "c59ef56fe16bdcc1fffd70b6e8a2fda4bf9c28fe" | ||
"gitHead": "80d228669adadb8dfcd24b8421517fed3be2d474" | ||
} |
/** | ||
* External imports | ||
* External dependencies | ||
*/ | ||
@@ -4,0 +4,0 @@ import { isPlainObject, isString } from 'lodash'; |
@@ -5,3 +5,3 @@ /** | ||
import { create } from 'rungen'; | ||
import { map, isString } from 'lodash'; | ||
import { map } from 'lodash'; | ||
import isPromise from 'is-promise'; | ||
@@ -12,3 +12,2 @@ | ||
*/ | ||
import castError from './cast-error'; | ||
import { isActionOfType, isAction } from './is-action'; | ||
@@ -32,8 +31,5 @@ | ||
// Async control routine awaits resolution. | ||
routine.then( | ||
yieldNext, | ||
( error ) => yieldError( castError( error ) ), | ||
); | ||
routine.then( yieldNext, yieldError ); | ||
} else { | ||
next( routine ); | ||
yieldNext( routine ); | ||
} | ||
@@ -57,3 +53,3 @@ return true; | ||
rungenRuntime( action, ( result ) => { | ||
if ( typeof result === 'object' && isString( result.type ) ) { | ||
if ( isAction( result ) ) { | ||
dispatch( result ); | ||
@@ -60,0 +56,0 @@ } |
@@ -53,2 +53,3 @@ /** | ||
it( 'should throw if promise rejects', async () => { | ||
expect.hasAssertions(); | ||
const middleware = createMiddleware( { | ||
@@ -64,3 +65,3 @@ WAIT_FAIL: () => new Promise( ( resolve, reject ) => | ||
} catch ( error ) { | ||
expect( error.message ).toBe( 'Message' ); | ||
expect( error ).toBe( 'Message' ); | ||
} | ||
@@ -73,2 +74,3 @@ } | ||
it( 'should throw if promise throws', () => { | ||
expect.hasAssertions(); | ||
const middleware = createMiddleware( { | ||
@@ -91,2 +93,27 @@ WAIT_FAIL: () => new Promise( () => { | ||
// Currently this test will not error even under conditions producing it but | ||
// instead will have an uncaught error/warning printed in the cli console: | ||
// - (node:37109) UnhandledPromiseRejectionWarning: TypeError: Cannot read | ||
// property 'type' of null (and others) | ||
// See this github thread for context: | ||
// https://github.com/facebook/jest/issues/3251 | ||
it( 'should handle a null returned from a caught promise error', () => { | ||
expect.hasAssertions(); | ||
const middleware = createMiddleware( { | ||
WAIT_FAIL: () => new Promise( () => { | ||
throw new Error( 'Message' ); | ||
} ), | ||
} ); | ||
const store = createStoreWithMiddleware( middleware ); | ||
function* createAction() { | ||
try { | ||
yield { type: 'WAIT_FAIL' }; | ||
} catch ( error ) { | ||
expect( error.message ).toBe( 'Message' ); | ||
return null; | ||
} | ||
} | ||
store.dispatch( createAction() ); | ||
} ); | ||
it( 'assigns sync controlled return value into yield assignment', () => { | ||
@@ -123,2 +150,19 @@ const middleware = createMiddleware( { | ||
} ); | ||
it( 'does not recurse when action like object returns from a sync ' + | ||
'control', () => { | ||
const post = { type: 'post' }; | ||
const middleware = createMiddleware( { | ||
UPDATE: () => post, | ||
} ); | ||
const store = createStoreWithMiddleware( middleware ); | ||
function* getPostAction() { | ||
const nextState = yield { type: 'UPDATE' }; | ||
return { type: 'CHANGE', nextState }; | ||
} | ||
store.dispatch( getPostAction() ); | ||
expect( store.getState() ).toEqual( post ); | ||
} ); | ||
} ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
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
58292
27
600
Updated@babel/runtime@^7.3.1