[@wordpress/redux-routine] add new definitions (#36688)

This commit is contained in:
Derek Sifford 2019-07-10 18:50:51 -04:00 committed by Armando Aguirre
parent 5710db716f
commit d2bf4fe0fa
5 changed files with 57 additions and 0 deletions

View File

@ -0,0 +1,20 @@
// Type definitions for @wordpress/redux-routine 3.4
// Project: https://github.com/WordPress/gutenberg/tree/master/packages/redux-routine/README.md
// Definitions by: Derek Sifford <https://github.com/dsifford>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 3.5
import { AnyAction, Middleware } from 'redux';
/**
* Creates a Redux middleware, given an object of controls where each key is an action type for
* which to act upon, the value a function which returns either a promise which is to resolve when
* evaluation of the action should continue, or a value. The value or resolved promise value is
* assigned on the return value of the yield assignment. If the control handler returns undefined,
* the execution is not continued.
*
* @param controls - Object of control handlers.
*/
declare function createMiddleware(controls?: Record<string, (action: AnyAction) => any>): Middleware;
export default createMiddleware;

View File

@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"redux": "^4.0.1"
}
}

View File

@ -0,0 +1,19 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"paths": {
"@wordpress/redux-routine": ["wordpress__redux-routine"]
}
},
"files": ["index.d.ts", "wordpress__redux-routine-tests.ts"]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@ -0,0 +1,11 @@
import { createStore, applyMiddleware } from 'redux';
import createMiddleware from '@wordpress/redux-routine';
const middleware = createMiddleware({
FOO: action => action.foo,
BAR(action) {
return action.bar;
},
});
const store = createStore(state => state, applyMiddleware(middleware));