Passed
Push — dev ( 65c6f9...40537c )
by
unknown
05:05 queued 10s
created

resources/assets/js/configureStore.ts   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 38
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 33
mnd 2
bc 2
fnc 0
dl 0
loc 38
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 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
    collapsed: true,
21
  });
22
23
  const isDev = process.env.NODE_ENV === "development";
24
25
  let middleware = isDev
26
    ? applyMiddleware(thunk, apiMiddleware, logger)
27
    : applyMiddleware(thunk, apiMiddleware);
28
29
  if (isDev) {
30
    middleware = composeWithDevTools(middleware);
31
  }
32
33
  const reducer = rootReducer();
34
  return createStore(reducer, middleware);
35
};
36
37
export default configureStore;
38