Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/redux-routine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ Creates a Redux middleware, given an object of controls where each key is an act

_Parameters_

- _controls_ `Record<string, (value: import('redux').AnyAction) => Promise<boolean> | boolean>`: Object of control handlers.
- _controls_ `Record< string, ( value: AnyAction ) => Promise< boolean > | boolean >`: Object of control handlers.

_Returns_

- `import('redux').Middleware`: Co-routine runtime
- `Middleware`: Co-routine runtime

<!-- END TOKEN(Autogenerated API docs) -->

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* External dependencies
*/
import type { Middleware, AnyAction } from 'redux';

/**
* Internal dependencies
*/
Expand All @@ -12,11 +17,16 @@ import createRuntime from './runtime';
* value of the yield assignment. If the control handler returns undefined, the
* execution is not continued.
*
* @param {Record<string, (value: import('redux').AnyAction) => Promise<boolean> | boolean>} controls Object of control handlers.
* @param controls Object of control handlers.
*
* @return {import('redux').Middleware} Co-routine runtime
* @return Co-routine runtime
*/
export default function createMiddleware( controls = {} ) {
export default function createMiddleware(
controls: Record<
string,
( value: AnyAction ) => Promise< boolean > | boolean
> = {}
): Middleware {
return ( store ) => {
const runtime = createRuntime( controls, store.dispatch );
return ( next ) => ( action ) => {
Expand Down
30 changes: 0 additions & 30 deletions packages/redux-routine/src/is-action.js

This file was deleted.

32 changes: 32 additions & 0 deletions packages/redux-routine/src/is-action.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* External dependencies
*/
import { isPlainObject } from 'is-plain-object';
import type { AnyAction } from 'redux';

/**
* Returns true if the given object quacks like an action.
*
* @param object Object to test
*
* @return Whether object is an action.
*/
export function isAction( object: any ): object is AnyAction {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let us use unknown instead of any here.

Suggested change
export function isAction( object: any ): object is AnyAction {
export function isAction( object: unknown ): object is Action {

We may need to add this to a types.ts file in the same directory

/**
 * Add type guard for isPlainObject until the below PR gets merged:
 *
 * @see https://github.com/jonschlinkert/is-plain-object/pull/29
 */

declare module 'is-plain-object' {
	export function isPlainObject(
		value: unknown
	): value is Record< PropertyKey, unknown >;
}

return isPlainObject( object ) && typeof object.type === 'string';
}

/**
* Returns true if the given object quacks like an action and has a specific
* action type
*
* @param object Object to test
* @param expectedType The expected type for the action.
*
* @return Whether object is an action and is of specific type.
*/
export function isActionOfType(
object: unknown,
expectedType: string
): object is AnyAction {
return isAction( object ) && object.type === expectedType;
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
/* eslint-disable jsdoc/valid-types */
/**
* Returns true if the given object is a generator, or false otherwise.
*
* @see https://www.ecma-international.org/ecma-262/6.0/#sec-generator-objects
*
* @param {any} object Object to test.
* @param object Object to test.
*
* @return {object is Generator} Whether object is a generator.
* @return Whether object is a generator.
*/
export default function isGenerator( object ) {
/* eslint-enable jsdoc/valid-types */
export default function isGenerator( object: any ): object is Generator {
// Check that iterator (next) and iterable (Symbol.iterator) interfaces are satisfied.
// These checks seem to be compatible with several generator helpers as well as the native implementation.
return (
Expand Down
Loading