Passed
Push — task/application-handle-step-s... ( 5a9035...2b5b8c )
by Yonathan
04:05
created

resources/assets/js/configureStore.ts   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 36
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 32
dl 0
loc 36
rs 10
c 0
b 0
f 0
wmc 2
mnd 2
bc 2
fnc 0
bpm 0
cpm 0
noi 0
1
import {
2
  applyMiddleware,
3
  createStore,
4
  AnyAction,
5
  Store,
6
  Dispatch,
7
} from "redux";
8
import thunk, { ThunkDispatch } from "redux-thunk";
9
import { composeWithDevTools } from "redux-devtools-extension";
10
import { createLogger } from "redux-logger";
11
import { apiMiddleware } from "redux-api-middleware";
12
import rootReducer, { RootState } from "./store/store";
13
14
/** Defining a dispatch for the app that accepts thunks */
15
export type DispatchType = Dispatch<AnyAction, RootState> &
16
  ThunkDispatch<any, any, AnyAction>;
17
18
export const configureStore = (): Store<RootState, AnyAction> => {
19
  const logger = createLogger();
20
21
  const isDev = process.env.NODE_ENV === "development";
22
23
  let middleware = isDev
24
    ? applyMiddleware(thunk, apiMiddleware, logger)
25
    : applyMiddleware(thunk, apiMiddleware);
26
27
  if (isDev) {
28
    middleware = composeWithDevTools(middleware);
29
  }
30
31
  const reducer = rootReducer();
32
  return createStore(reducer, middleware);
33
};
34
35
export default configureStore;
36