All files / app/store configureStore.dev.ts

0% Statements 0/27
0% Branches 0/3
0% Functions 0/2
0% Lines 0/25

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71                                                                                                                                             
/* eslint-disable @typescript-eslint/no-unsafe-argument */
 
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
 
/* eslint-disable @typescript-eslint/no-var-requires */
import { RootState, createRootReducer, persistConfig } from '.';
import { createStore, applyMiddleware, compose } from '@reduxjs/toolkit';
import { getInitialStateFromDisk } from '@utils/disk-store';
import { routerMiddleware, routerActions } from 'connected-react-router';
import { createHashHistory } from 'history';
import { persistStore, persistReducer } from 'redux-persist';
import thunk from 'redux-thunk';
 
declare global {
  interface Window {
    __REDUX_DEVTOOLS_EXTENSION_COMPOSE__: (obj: Record<string, unknown>) => typeof compose;
  }
  interface NodeModule {
    hot?: {
      accept: (path: string, cb: () => void) => void;
    };
  }
}
 
export const history = createHashHistory();
 
const rootReducer = createRootReducer({ history, keys: getInitialStateFromDisk() });
 
export const configureStore = (initialState?: RootState) => {
  // Redux Configuration
  const middleware = [];
  const enhancers = [];
 
  // Thunk Middleware
  middleware.push(thunk);
 
  // Router Middleware
  const router = routerMiddleware(history);
  middleware.push(router);
 
  // Redux DevTools Configuration
  const actionCreators = {
    ...routerActions,
  };
  // If Redux DevTools Extension is installed use it, otherwise use Redux compose
  /* eslint-disable no-underscore-dangle */
  const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
    ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
        // Options: http://extension.remotedev.io/docs/API/Arguments.html
        actionCreators,
      })
    : compose;
 
  // Apply Middleware & Compose Enhancers
  enhancers.push(applyMiddleware(...middleware));
  const enhancer = composeEnhancers<any>(...enhancers);
 
  const persistedReducer = persistReducer(persistConfig, rootReducer as any);
 
  // Create Store
  const store = createStore(persistedReducer, initialState, enhancer);
 
  const persistor = persistStore(store);
 
  Iif (module.hot) {
    module.hot.accept('./index', () => store.replaceReducer(require('./index').default));
  }
 
  return { store, persistor };
};