From c678ec6b9292f5ba4443482398223e03d75b07eb Mon Sep 17 00:00:00 2001 From: jero Date: Sun, 29 Sep 2019 03:44:26 +0300 Subject: [PATCH] refactor(types): create MiddlewareTypes move ApiMiddlewareType and import it from there, also remove useless $FlowIgnore comments improves #34, #35 --- src/app/shared/types/MiddlewareTypes.js | 5 +++++ src/app/store/config/enhancer.js | 3 +-- .../config/middlewares/apiMiddleware/apiMiddleware.js | 11 +---------- 3 files changed, 7 insertions(+), 12 deletions(-) create mode 100644 src/app/shared/types/MiddlewareTypes.js diff --git a/src/app/shared/types/MiddlewareTypes.js b/src/app/shared/types/MiddlewareTypes.js new file mode 100644 index 00000000..b9fda835 --- /dev/null +++ b/src/app/shared/types/MiddlewareTypes.js @@ -0,0 +1,5 @@ +// @flow strict +import type { State } from '@/shared/types/State'; +import type { Actions } from '@/shared/types/Actions'; + +export type ApiMiddlewareType = Middleware; diff --git a/src/app/store/config/enhancer.js b/src/app/store/config/enhancer.js index c851cb29..f0ad2923 100644 --- a/src/app/store/config/enhancer.js +++ b/src/app/store/config/enhancer.js @@ -16,8 +16,7 @@ const devtools = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({ actionsBlacklist: [] }); /* eslint-enable */ const composeEnhancers = devtools || compose; -// eslint-disable-next-line no-underscore-dangle -// $FlowFixMe + const enhancer: EnhancerType = composeEnhancers(applyMiddleware(...middlewares)); export default enhancer; diff --git a/src/app/store/config/middlewares/apiMiddleware/apiMiddleware.js b/src/app/store/config/middlewares/apiMiddleware/apiMiddleware.js index 684bd2f4..d7e4feb3 100644 --- a/src/app/store/config/middlewares/apiMiddleware/apiMiddleware.js +++ b/src/app/store/config/middlewares/apiMiddleware/apiMiddleware.js @@ -1,14 +1,8 @@ /* eslint-disable consistent-return */ // @flow strict -import type { Dispatch, Middleware } from 'redux'; - -import type { State } from '@/shared/types/State'; -import type { Actions } from '@/shared/types/Actions'; import type { ApiMetaType } from '@/shared/types/CommonType'; +import type { ApiMiddlewareType } from '@/shared/types/MiddlewareTypes'; -type ApiMiddlewareType = Middleware>; - -// $FlowIgnore - middlewares dispatch actions and not return anything const apiMiddleware: ApiMiddlewareType = ({ dispatch, getState }) => (next) => (action) => { let meta: ApiMetaType = {}; @@ -44,7 +38,6 @@ const apiMiddleware: ApiMiddlewareType = ({ dispatch, getState }) => (next) => ( } if (!shouldCallAPI(getState())) { - // $FlowIgnore return; } @@ -58,8 +51,6 @@ const apiMiddleware: ApiMiddlewareType = ({ dispatch, getState }) => (next) => ( (async () => { try { const response: Response = await callAPI(); - // eslint-disable-next-line no-console - // console.log('response', response); return dispatch({ payload: { response }, type: successType,