2020-04-10 01:53:33 +02:00
|
|
|
import { configureStore as reduxConfigureStore, getDefaultMiddleware } from '@reduxjs/toolkit';
|
2019-06-03 13:40:33 +02:00
|
|
|
import { createLogger } from 'redux-logger';
|
2020-04-10 10:08:42 +02:00
|
|
|
import { ThunkMiddleware } from 'redux-thunk';
|
2018-11-05 16:54:48 +01:00
|
|
|
import { setStore } from './store';
|
2019-06-03 13:40:33 +02:00
|
|
|
import { StoreState } from 'app/types/store';
|
|
|
|
|
import { toggleLogActionsMiddleware } from 'app/core/middlewares/application';
|
2019-10-08 21:37:07 -07:00
|
|
|
import { addReducer, createRootReducer } from '../core/reducers/root';
|
2020-01-13 08:03:22 +01:00
|
|
|
import { buildInitialState } from '../core/reducers/navModel';
|
2019-10-04 05:24:47 -07:00
|
|
|
|
|
|
|
|
export function addRootReducer(reducers: any) {
|
2019-10-08 21:37:07 -07:00
|
|
|
// this is ok now because we add reducers before configureStore is called
|
|
|
|
|
// in the future if we want to add reducers during runtime
|
|
|
|
|
// we'll have to solve this in a more dynamic way
|
|
|
|
|
addReducer(reducers);
|
2019-10-04 05:24:47 -07:00
|
|
|
}
|
2018-10-16 15:36:33 +02:00
|
|
|
|
2021-02-10 15:23:19 +01:00
|
|
|
export function configureStore(initialState?: Partial<StoreState>) {
|
2019-06-03 13:40:33 +02:00
|
|
|
const logger = createLogger({
|
2021-01-20 07:59:48 +01:00
|
|
|
predicate: (getState) => {
|
2019-06-03 13:40:33 +02:00
|
|
|
return getState().application.logActions;
|
|
|
|
|
},
|
|
|
|
|
});
|
2018-10-16 15:36:33 +02:00
|
|
|
|
2020-04-10 10:08:42 +02:00
|
|
|
const middleware = process.env.NODE_ENV !== 'production' ? [toggleLogActionsMiddleware, logger] : [];
|
|
|
|
|
|
|
|
|
|
const reduxDefaultMiddleware = getDefaultMiddleware<StoreState>({
|
|
|
|
|
thunk: true,
|
|
|
|
|
serializableCheck: false,
|
|
|
|
|
immutableCheck: false,
|
|
|
|
|
} as any);
|
2020-01-13 08:03:22 +01:00
|
|
|
|
2020-01-28 09:13:56 +01:00
|
|
|
const store = reduxConfigureStore<StoreState>({
|
2020-01-13 08:03:22 +01:00
|
|
|
reducer: createRootReducer(),
|
2020-04-10 10:08:42 +02:00
|
|
|
middleware: [...reduxDefaultMiddleware, ...middleware] as [ThunkMiddleware<StoreState>],
|
2020-01-13 08:03:22 +01:00
|
|
|
devTools: process.env.NODE_ENV !== 'production',
|
|
|
|
|
preloadedState: {
|
|
|
|
|
navIndex: buildInitialState(),
|
2021-02-10 15:23:19 +01:00
|
|
|
...initialState,
|
2020-01-13 08:03:22 +01:00
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
|
2019-06-04 16:20:55 +02:00
|
|
|
setStore(store);
|
|
|
|
|
return store;
|
2018-07-09 09:17:38 +02:00
|
|
|
}
|
2020-04-10 10:08:42 +02:00
|
|
|
|
2021-02-10 15:23:19 +01:00
|
|
|
/*
|
2020-04-10 10:08:42 +02:00
|
|
|
function getActionsToIgnoreSerializableCheckOn() {
|
|
|
|
|
return [
|
|
|
|
|
'dashboard/setPanelAngularComponent',
|
|
|
|
|
'dashboard/panelModelAndPluginReady',
|
|
|
|
|
'dashboard/dashboardInitCompleted',
|
|
|
|
|
'plugins/panelPluginLoaded',
|
|
|
|
|
'explore/initializeExplore',
|
|
|
|
|
'explore/changeRange',
|
|
|
|
|
'explore/updateDatasourceInstance',
|
|
|
|
|
'explore/queryStoreSubscription',
|
|
|
|
|
'explore/queryStreamUpdated',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function getPathsToIgnoreMutationAndSerializableCheckOn() {
|
2021-02-10 15:23:19 +01:00
|
|
|
return [
|
2020-04-10 10:08:42 +02:00
|
|
|
'plugins.panels',
|
|
|
|
|
'dashboard.panels',
|
|
|
|
|
'dashboard.getModel',
|
|
|
|
|
'payload.plugin',
|
|
|
|
|
'panelEditorNew.getPanel',
|
|
|
|
|
'panelEditorNew.getSourcePanel',
|
|
|
|
|
'panelEditorNew.getData',
|
|
|
|
|
'explore.left.queryResponse',
|
|
|
|
|
'explore.right.queryResponse',
|
|
|
|
|
'explore.left.datasourceInstance',
|
|
|
|
|
'explore.right.datasourceInstance',
|
|
|
|
|
'explore.left.range',
|
|
|
|
|
'explore.left.eventBridge',
|
|
|
|
|
'explore.right.eventBridge',
|
|
|
|
|
'explore.right.range',
|
|
|
|
|
'explore.left.querySubscription',
|
2021-02-10 15:23:19 +01:00
|
|
|
'explore.right.querySubscription',
|
2020-04-10 10:08:42 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
*/
|