configureStore.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { configureStore as reduxConfigureStore, MiddlewareArray } from '@reduxjs/toolkit';
  2. import { AnyAction } from 'redux';
  3. import { ThunkMiddleware } from 'redux-thunk';
  4. import { StoreState } from 'app/types/store';
  5. import { buildInitialState } from '../core/reducers/navModel';
  6. import { addReducer, createRootReducer } from '../core/reducers/root';
  7. import { setStore } from './store';
  8. export function addRootReducer(reducers: any) {
  9. // this is ok now because we add reducers before configureStore is called
  10. // in the future if we want to add reducers during runtime
  11. // we'll have to solve this in a more dynamic way
  12. addReducer(reducers);
  13. }
  14. export function configureStore(initialState?: Partial<StoreState>) {
  15. const store = reduxConfigureStore<StoreState, AnyAction, MiddlewareArray<[ThunkMiddleware<StoreState, AnyAction>]>>({
  16. reducer: createRootReducer(),
  17. middleware: (getDefaultMiddleware) =>
  18. getDefaultMiddleware({ thunk: true, serializableCheck: false, immutableCheck: false }),
  19. devTools: process.env.NODE_ENV !== 'production',
  20. preloadedState: {
  21. navIndex: buildInitialState(),
  22. ...initialState,
  23. },
  24. });
  25. setStore(store);
  26. return store;
  27. }
  28. /*
  29. function getActionsToIgnoreSerializableCheckOn() {
  30. return [
  31. 'dashboard/setPanelAngularComponent',
  32. 'dashboard/panelModelAndPluginReady',
  33. 'dashboard/dashboardInitCompleted',
  34. 'plugins/panelPluginLoaded',
  35. 'explore/initializeExplore',
  36. 'explore/changeRange',
  37. 'explore/updateDatasourceInstance',
  38. 'explore/queryStoreSubscription',
  39. 'explore/queryStreamUpdated',
  40. ];
  41. }
  42. function getPathsToIgnoreMutationAndSerializableCheckOn() {
  43. return [
  44. 'plugins.panels',
  45. 'dashboard.panels',
  46. 'dashboard.getModel',
  47. 'payload.plugin',
  48. 'panelEditorNew.getPanel',
  49. 'panelEditorNew.getSourcePanel',
  50. 'panelEditorNew.getData',
  51. 'explore.left.queryResponse',
  52. 'explore.right.queryResponse',
  53. 'explore.left.datasourceInstance',
  54. 'explore.right.datasourceInstance',
  55. 'explore.left.range',
  56. 'explore.left.eventBridge',
  57. 'explore.right.eventBridge',
  58. 'explore.right.range',
  59. 'explore.left.querySubscription',
  60. 'explore.right.querySubscription',
  61. ];
  62. }
  63. */