FIX;Api Middleware types

This commit is contained in:
Roman Jaroš 2020-12-02 08:12:38 +01:00
parent e06c43678d
commit a6b717769d

View file

@ -1,4 +1,4 @@
import { AnyAction, Middleware } from 'redux'; import { Action, Middleware } from 'redux';
import { is } from 'ramda'; import { is } from 'ramda';
import { IAction } from '@romanjaros/treejs-types/redux/actions'; import { IAction } from '@romanjaros/treejs-types/redux/actions';
@ -8,15 +8,20 @@ import { IFetchConfig } from './types';
import { fetchStatusActions } from './actions'; import { fetchStatusActions } from './actions';
import { FetchActions } from './constants'; import { FetchActions } from './constants';
import { resolveParams } from './utils'; import { resolveParams } from './utils';
import { ThunkAction, ThunkDispatch } from 'redux-thunk';
interface ISettings<C> { interface ISettings<C> {
BASE_ENDPOINT_URL: string; BASE_ENDPOINT_URL: string;
onError?: (error: any, setting: IFetchConfig<C>) => AnyAction; onError?: (error: any, setting: IFetchConfig<C>) => ThunkAction<void, any, unknown, Action<string>>;
} }
export const apiMiddleware = <C extends unknown>(setting: ISettings<C>): Middleware => (store) => (next) => async ( type IStore = {
action: IAction<IFetchConfig<C>> dispatch: ThunkDispatch<any, unknown, Action<string>>;
) => { };
export const apiMiddleware = <C extends unknown>(setting: ISettings<C>): Middleware => (store: IStore) => (
next
) => async (action: IAction<IFetchConfig<C>>) => {
if (action.type === FetchActions.FETCH) { if (action.type === FetchActions.FETCH) {
if (isNilOrEmpty(action.payload.url)) { if (isNilOrEmpty(action.payload.url)) {
throw `URL '${action.payload.url}' is not valid, please specify valid URL!`; throw `URL '${action.payload.url}' is not valid, please specify valid URL!`;