@wordpress/redux-routine
Version:
Redux middleware for generator coroutines.
8 lines (7 loc) • 1.63 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/index.ts"],
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { Middleware, AnyAction } from 'redux';\n\n/**\n * Internal dependencies\n */\nimport isGenerator from './is-generator';\nimport createRuntime from './runtime';\n\n/**\n * Creates a Redux middleware, given an object of controls where each key is an\n * action type for which to act upon, the value a function which returns either\n * a promise which is to resolve when evaluation of the action should continue,\n * or a value. The value or resolved promise value is assigned on the return\n * value of the yield assignment. If the control handler returns undefined, the\n * execution is not continued.\n *\n * @param controls Object of control handlers.\n *\n * @return Co-routine runtime\n */\nexport default function createMiddleware(\n\tcontrols: Record<\n\t\tstring,\n\t\t( value: AnyAction ) => Promise< boolean > | boolean\n\t> = {}\n): Middleware {\n\treturn ( store ) => {\n\t\tconst runtime = createRuntime( controls, store.dispatch );\n\t\treturn ( next ) => ( action ) => {\n\t\t\tif ( ! isGenerator( action ) ) {\n\t\t\t\treturn next( action );\n\t\t\t}\n\n\t\t\treturn runtime( action );\n\t\t};\n\t};\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,0BAAwB;AACxB,qBAA0B;AAcX,SAAR,iBACN,WAGI,CAAC,GACQ;AACb,SAAO,CAAE,UAAW;AACnB,UAAM,cAAU,eAAAA,SAAe,UAAU,MAAM,QAAS;AACxD,WAAO,CAAE,SAAU,CAAE,WAAY;AAChC,UAAK,KAAE,oBAAAC,SAAa,MAAO,GAAI;AAC9B,eAAO,KAAM,MAAO;AAAA,MACrB;AAEA,aAAO,QAAS,MAAO;AAAA,IACxB;AAAA,EACD;AACD;",
"names": ["createRuntime", "isGenerator"]
}