| [a762898] | 1 | import { autoBatchEnhancer, combineReducers, configureStore } from '@reduxjs/toolkit';
|
|---|
| 2 | import { optionsReducer } from './optionsSlice';
|
|---|
| 3 | import { tooltipReducer } from './tooltipSlice';
|
|---|
| 4 | import { chartDataReducer } from './chartDataSlice';
|
|---|
| 5 | import { chartLayoutReducer } from './layoutSlice';
|
|---|
| 6 | import { mouseClickMiddleware, mouseMoveMiddleware } from './mouseEventsMiddleware';
|
|---|
| 7 | import { reduxDevtoolsJsonStringifyReplacer } from './reduxDevtoolsJsonStringifyReplacer';
|
|---|
| 8 | import { cartesianAxisReducer } from './cartesianAxisSlice';
|
|---|
| 9 | import { graphicalItemsReducer } from './graphicalItemsSlice';
|
|---|
| 10 | import { referenceElementsReducer } from './referenceElementsSlice';
|
|---|
| 11 | import { brushReducer } from './brushSlice';
|
|---|
| 12 | import { legendReducer } from './legendSlice';
|
|---|
| 13 | import { rootPropsReducer } from './rootPropsSlice';
|
|---|
| 14 | import { polarAxisReducer } from './polarAxisSlice';
|
|---|
| 15 | import { polarOptionsReducer } from './polarOptionsSlice';
|
|---|
| 16 | import { keyboardEventsMiddleware } from './keyboardEventsMiddleware';
|
|---|
| 17 | import { externalEventsMiddleware } from './externalEventsMiddleware';
|
|---|
| 18 | import { touchEventMiddleware } from './touchEventsMiddleware';
|
|---|
| 19 | import { errorBarReducer } from './errorBarSlice';
|
|---|
| 20 | import { Global } from '../util/Global';
|
|---|
| 21 | import { zIndexReducer } from './zIndexSlice';
|
|---|
| 22 | var rootReducer = combineReducers({
|
|---|
| 23 | brush: brushReducer,
|
|---|
| 24 | cartesianAxis: cartesianAxisReducer,
|
|---|
| 25 | chartData: chartDataReducer,
|
|---|
| 26 | errorBars: errorBarReducer,
|
|---|
| 27 | graphicalItems: graphicalItemsReducer,
|
|---|
| 28 | layout: chartLayoutReducer,
|
|---|
| 29 | legend: legendReducer,
|
|---|
| 30 | options: optionsReducer,
|
|---|
| 31 | polarAxis: polarAxisReducer,
|
|---|
| 32 | polarOptions: polarOptionsReducer,
|
|---|
| 33 | referenceElements: referenceElementsReducer,
|
|---|
| 34 | rootProps: rootPropsReducer,
|
|---|
| 35 | tooltip: tooltipReducer,
|
|---|
| 36 | zIndex: zIndexReducer
|
|---|
| 37 | });
|
|---|
| 38 | export var createRechartsStore = function createRechartsStore(preloadedState) {
|
|---|
| 39 | var chartName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'Chart';
|
|---|
| 40 | return configureStore({
|
|---|
| 41 | reducer: rootReducer,
|
|---|
| 42 | // redux-toolkit v1 types are unhappy with the preloadedState type. Remove the `as any` when bumping to v2
|
|---|
| 43 | preloadedState: preloadedState,
|
|---|
| 44 | // @ts-expect-error redux-toolkit v1 types are unhappy with the middleware array. Remove this comment when bumping to v2
|
|---|
| 45 | middleware: getDefaultMiddleware => {
|
|---|
| 46 | var _process$env$NODE_ENV;
|
|---|
| 47 | return getDefaultMiddleware({
|
|---|
| 48 | serializableCheck: false,
|
|---|
| 49 | immutableCheck: !['commonjs', 'es6', 'production'].includes((_process$env$NODE_ENV = "es6") !== null && _process$env$NODE_ENV !== void 0 ? _process$env$NODE_ENV : '')
|
|---|
| 50 | }).concat([mouseClickMiddleware.middleware, mouseMoveMiddleware.middleware, keyboardEventsMiddleware.middleware, externalEventsMiddleware.middleware, touchEventMiddleware.middleware]);
|
|---|
| 51 | },
|
|---|
| 52 | /*
|
|---|
| 53 | * I can't find out how to satisfy typescript here.
|
|---|
| 54 | * We return `EnhancerArray<[StoreEnhancer<{}, {}>, StoreEnhancer]>` from this function,
|
|---|
| 55 | * but the types say we should return `EnhancerArray<StoreEnhancer<{}, {}>`.
|
|---|
| 56 | * Looks like it's badly inferred generics, but it won't allow me to provide the correct type manually either.
|
|---|
| 57 | * So let's just ignore the error for now.
|
|---|
| 58 | */
|
|---|
| 59 | // @ts-expect-error mismatched generics
|
|---|
| 60 | enhancers: getDefaultEnhancers => {
|
|---|
| 61 | var enhancers = getDefaultEnhancers;
|
|---|
| 62 | if (typeof getDefaultEnhancers === 'function') {
|
|---|
| 63 | /*
|
|---|
| 64 | * In RTK v2 this is always a function, but in v1 it is an array.
|
|---|
| 65 | * Because we have @types/redux-toolkit v1 as a dependency, typescript is going to flag this as an error.
|
|---|
| 66 | * We support both RTK v1 and v2, so we need to do this check.
|
|---|
| 67 | * https://redux-toolkit.js.org/usage/migrating-rtk-2#configurestoreenhancers-must-be-a-callback
|
|---|
| 68 | */
|
|---|
| 69 | // @ts-expect-error RTK v2 behaviour on RTK v1 types
|
|---|
| 70 | enhancers = getDefaultEnhancers();
|
|---|
| 71 | }
|
|---|
| 72 | return enhancers.concat(autoBatchEnhancer({
|
|---|
| 73 | type: 'raf'
|
|---|
| 74 | }));
|
|---|
| 75 | },
|
|---|
| 76 | devTools: Global.devToolsEnabled && {
|
|---|
| 77 | serialize: {
|
|---|
| 78 | replacer: reduxDevtoolsJsonStringifyReplacer
|
|---|
| 79 | },
|
|---|
| 80 | name: "recharts-".concat(chartName)
|
|---|
| 81 | }
|
|---|
| 82 | });
|
|---|
| 83 | }; |
|---|