store.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { configureStore } from '@reduxjs/toolkit';
  2. import { rootReducer } from '../reducers';
  3. import { errorsMiddleware } from './middlewares/errors';
  4. import { loadingBarMiddleware } from './middlewares/loading_bar';
  5. import { soundsMiddleware } from './middlewares/sounds';
  6. export const store = configureStore({
  7. reducer: rootReducer,
  8. middleware: (getDefaultMiddleware) =>
  9. getDefaultMiddleware({
  10. // In development, Redux Toolkit enables 2 default middlewares to detect
  11. // common issues with states. Unfortunately, our use of ImmutableJS for state
  12. // triggers both, so lets disable them until our state is fully refactored
  13. // https://redux-toolkit.js.org/api/serializabilityMiddleware
  14. // This checks recursively that every values in the state are serializable in JSON
  15. // Which is not the case, as we use ImmutableJS structures, but also File objects
  16. serializableCheck: false,
  17. // https://redux-toolkit.js.org/api/immutabilityMiddleware
  18. // This checks recursively if every value in the state is immutable (ie, a JS primitive type)
  19. // But this is not the case, as our Root State is an ImmutableJS map, which is an object
  20. immutableCheck: false,
  21. })
  22. .concat(
  23. loadingBarMiddleware({
  24. promiseTypeSuffixes: ['REQUEST', 'SUCCESS', 'FAIL'],
  25. }),
  26. )
  27. .concat(errorsMiddleware)
  28. .concat(soundsMiddleware()),
  29. });
  30. // Infer the `RootState` and `AppDispatch` types from the store itself
  31. export type RootState = ReturnType<typeof rootReducer>;
  32. export type AppDispatch = typeof store.dispatch;
  33. export type GetState = typeof store.getState;