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' ;
@@ -54,18 +54,43 @@ export const codeAssistBackend = window.code_assist_backend;
5454
5555const isSingleClusterMode = `${ metaBackend } ` === 'undefined' ;
5656
57+ export interface ConfigureStoreOptions {
58+ aRootReducer ?: Reducer ;
59+ singleClusterMode ?: boolean ;
60+ api ?: YdbEmbeddedAPI ;
61+ additionalReducers ?: Record < string , Reducer > ;
62+ }
63+
5764export function configureStore ( {
58- aRootReducer = rootReducer ,
65+ aRootReducer,
5966 singleClusterMode = isSingleClusterMode ,
6067 api = new YdbEmbeddedAPI ( { webVersion, withCredentials : ! customBackend } ) ,
61- } = { } ) {
68+ additionalReducers = { } ,
69+ } : ConfigureStoreOptions = { } ) {
6270 ( { backend, basename, clusterName} = getUrlData ( {
6371 singleClusterMode,
6472 customBackend,
6573 } ) ) ;
6674 const history = createBrowserHistory ( { basename} ) ;
6775
68- const store = _configureStore ( aRootReducer , history , { singleClusterMode} , [
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} , [
6994 storeApi . middleware ,
7095 ] ) ;
7196 listenForHistoryChange ( store , history ) ;
0 commit comments