1- import { configureStore as configureReduxStore } from '@reduxjs/toolkit' ;
1+ import { combineReducers , configureStore as configureReduxStore } from '@reduxjs/toolkit' ;
22import type { Action , Dispatch , Middleware , Reducer , UnknownAction } from '@reduxjs/toolkit' ;
33import type { History } from 'history' ;
44import { createBrowserHistory } from 'history' ;
@@ -7,7 +7,7 @@ import {listenForHistoryChange} from 'redux-location-state';
77import { YdbEmbeddedAPI } from '../services/api' ;
88
99import { getUrlData } from './getUrlData' ;
10- import rootReducer from './reducers' ;
10+ import combinedRootReducer , { rootReducer } from './reducers' ;
1111import { api as storeApi } from './reducers/api' ;
1212import { syncUserSettingsFromLS } from './reducers/settings/settings' ;
1313import { UPDATE_REF } from './reducers/tooltip' ;
@@ -51,19 +51,18 @@ export const webVersion = window.web_version;
5151export const customBackend = window . custom_backend ;
5252export const metaBackend = window . meta_backend ;
5353export const codeAssistBackend = window . code_assist_backend ;
54- export const aiAssistBackend = window . ai_assist_backend ;
5554
5655const isSingleClusterMode = `${ metaBackend } ` === 'undefined' ;
5756
5857export interface ConfigureStoreOptions {
59- aRootReducer ?: typeof rootReducer ;
58+ aRootReducer ?: Reducer ;
6059 singleClusterMode ?: boolean ;
6160 api ?: YdbEmbeddedAPI ;
6261 additionalReducers ?: Record < string , Reducer > ;
6362}
6463
6564export function configureStore ( {
66- aRootReducer = rootReducer ,
65+ aRootReducer,
6766 singleClusterMode = isSingleClusterMode ,
6867 api = new YdbEmbeddedAPI ( { webVersion, withCredentials : ! customBackend } ) ,
6968 additionalReducers = { } ,
@@ -74,21 +73,26 @@ export function configureStore({
7473 } ) ) ;
7574 const history = createBrowserHistory ( { basename} ) ;
7675
77- // Merge root reducer with additional reducers
78- const mergedReducer =
79- Object . keys ( additionalReducers ) . length > 0
80- ? {
81- ...aRootReducer ,
82- ...additionalReducers ,
83- }
84- : aRootReducer ;
85-
86- const store = _configureStore (
87- mergedReducer as typeof rootReducer ,
88- history ,
89- { singleClusterMode} ,
90- [ storeApi . middleware ] ,
91- ) ;
76+ // Create the final reducer
77+ let finalReducer : Reducer ;
78+
79+ if ( aRootReducer ) {
80+ // If custom root reducer is provided, use it
81+ finalReducer = aRootReducer ;
82+ } else if ( Object . keys ( additionalReducers ) . length > 0 ) {
83+ // If additional reducers are provided, combine them with the default ones
84+ finalReducer = combineReducers ( {
85+ ...rootReducer ,
86+ ...additionalReducers ,
87+ } ) ;
88+ } else {
89+ // Otherwise use the default combined reducer
90+ finalReducer = combinedRootReducer ;
91+ }
92+
93+ const store = _configureStore ( finalReducer , history , { singleClusterMode} , [
94+ storeApi . middleware ,
95+ ] ) ;
9296 listenForHistoryChange ( store , history ) ;
9397
9498 window . api = api ;
0 commit comments