diff --git a/src/app/store/middlewares/logger.js b/src/app/store/middlewares/logger.js index bfba19e4..60eb1d43 100644 --- a/src/app/store/middlewares/logger.js +++ b/src/app/store/middlewares/logger.js @@ -1,3 +1,10 @@ +// @flow strict + +import type { Dispatch, Middleware } from 'redux'; + +import type { State } from '@/store/types/State'; +import type { Actions, MiddlewareAction } from '@/store/types/Actions'; + /* eslint-disable no-console */ /** * Taken from: https://github.com/gaearon/todos/blob/17-the-middleware-chain/src/configureStore.js @@ -7,13 +14,14 @@ * @param {Object} store - Redux's store * @return {Function} */ -export default function logger(store) { +const logger: Middleware>> = (store) => { + /** * Rather than take the next middleware from the store, we'll * make it injectable as an argument, so the function that calls - * the middlewares can chose which middle ware to pass + * the middlewares can chose which middleware to pass */ - return (next) => { + return (next) => { if (!console.group) { return next; } @@ -25,10 +33,13 @@ export default function logger(store) { console.log('%c action', 'color: blue', action); const returnValue = next(action); console.log('%c next state', 'color: green', store.getState()); + // $FlowIgnore console.groupEnd(action.type); return returnValue; }; }; -} \ No newline at end of file +}; + +export default logger; diff --git a/src/app/store/types/Actions.js b/src/app/store/types/Actions.js index 98708fe0..4292d443 100644 --- a/src/app/store/types/Actions.js +++ b/src/app/store/types/Actions.js @@ -4,3 +4,14 @@ import type { ProductActionType } from '@/store/types/ProductsType'; export type Actions = ProductActionType + +export type ApiMiddlewareAction = { + type: string, + types?: Array, + callAPI?: () => Promise<*>, + shouldCallAPI?: (S) => boolean, + payload?: *, +}; + +export type MiddlewareAction = + ApiMiddlewareAction