redux-tiles
Version:
Library to create and easily compose redux pieces together in less verbose manner
24 lines (19 loc) • 777 B
text/typescript
import { Action, Dispatch, Middleware } from 'redux';
import { IPromiseObject } from './tiles/types';
import { waitTiles } from './waitTiles';
export function createMiddleware(paramsToInject: any = {}): { middleware: Middleware, waitTiles: Function} {
const promisesStorage: IPromiseObject = {};
const middleware: Middleware = (
{ dispatch, getState }: { dispatch: Dispatch<any>, getState(): any }
): ((next: Dispatch<any>) => Dispatch<any>) =>
(next: Dispatch<any>): Dispatch<any> => (action: Action): Action => {
if (typeof action === 'function') {
return action({ dispatch, getState, promisesStorage, ...paramsToInject });
}
return next(action);
};
return {
middleware,
waitTiles: waitTiles.bind(null, promisesStorage)
};
}