-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathconfigureStore.ts
77 lines (64 loc) · 2.73 KB
/
configureStore.ts
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
72
73
74
75
76
77
import {configureStore as configureReduxStore} from '@reduxjs/toolkit';
import type {Action, Dispatch, Middleware, Reducer, UnknownAction} from '@reduxjs/toolkit';
import type {History} from 'history';
import {createBrowserHistory} from 'history';
import {listenForHistoryChange} from 'redux-location-state';
import {YdbEmbeddedAPI} from '../services/api';
import {getUrlData} from './getUrlData';
import rootReducer from './reducers';
import {api as storeApi} from './reducers/api';
import {syncUserSettingsFromLS} from './reducers/settings/settings';
import {UPDATE_REF} from './reducers/tooltip';
import getLocationMiddleware from './state-url-mapping';
export let backend: string | undefined, basename: string, clusterName: string | undefined;
function _configureStore<
S = any,
A extends Action = UnknownAction,
P = S,
M extends Middleware<{}, S, Dispatch> = any,
>(aRootReducer: Reducer<S, A, P>, history: History, preloadedState: P, middleware: M[]) {
const {locationMiddleware, reducersWithLocation} = getLocationMiddleware(history, aRootReducer);
const store = configureReduxStore({
reducer: reducersWithLocation,
preloadedState,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
immutableCheck: window.react_app_disable_checks
? false
: {
ignoredPaths: ['tooltip.currentHoveredRef'],
},
serializableCheck: window.react_app_disable_checks
? false
: {
ignoredPaths: ['tooltip.currentHoveredRef', 'api'],
ignoredActions: [UPDATE_REF, 'api/sendQuery/rejected'],
},
}).concat(locationMiddleware, ...middleware),
});
syncUserSettingsFromLS(store);
return store;
}
export const webVersion = window.web_version;
export const customBackend = window.custom_backend;
export const metaBackend = window.meta_backend;
export const codeAssistBackend = window.code_assist_backend;
const isSingleClusterMode = `${metaBackend}` === 'undefined';
export function configureStore({
aRootReducer = rootReducer,
singleClusterMode = isSingleClusterMode,
api = new YdbEmbeddedAPI({webVersion, withCredentials: !customBackend}),
} = {}) {
({backend, basename, clusterName} = getUrlData({
href: window.location.href,
singleClusterMode,
customBackend,
}));
const history = createBrowserHistory({basename});
const store = _configureStore(aRootReducer, history, {singleClusterMode}, [
storeApi.middleware,
]);
listenForHistoryChange(store, history);
window.api = api;
return {history, store};
}