github.com/minio/console@v1.4.1/web-app/src/store.ts (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2021 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 import { TypedUseSelectorHook, useDispatch, useSelector } from "react-redux"; 18 import { combineReducers, configureStore } from "@reduxjs/toolkit"; 19 20 import systemReducer from "./systemSlice"; 21 import loginReducer from "./screens/LoginPage/loginSlice"; 22 import traceReducer from "./screens/Console/Trace/traceSlice"; 23 import logReducer from "./screens/Console/Logs/logsSlice"; 24 import healthInfoReducer from "./screens/Console/HealthInfo/healthInfoSlice"; 25 import watchReducer from "./screens/Console/Watch/watchSlice"; 26 import consoleReducer from "./screens/Console/consoleSlice"; 27 import addBucketsReducer from "./screens/Console/Buckets/ListBuckets/AddBucket/addBucketsSlice"; 28 import bucketDetailsReducer from "./screens/Console/Buckets/BucketDetails/bucketDetailsSlice"; 29 import objectBrowserReducer from "./screens/Console/ObjectBrowser/objectBrowserSlice"; 30 import dashboardReducer from "./screens/Console/Dashboard/dashboardSlice"; 31 import createUserReducer from "./screens/Console/Users/AddUsersSlice"; 32 import licenseReducer from "./screens/Console/License/licenseSlice"; 33 import registerReducer from "./screens/Console/Support/registerSlice"; 34 import destinationSlice from "./screens/Console/EventDestinations/destinationsSlice"; 35 import { objectBrowserWSMiddleware } from "./websockets/objectBrowserWSMiddleware"; 36 37 let objectsWS: WebSocket; 38 39 const rootReducer = combineReducers({ 40 system: systemReducer, 41 login: loginReducer, 42 trace: traceReducer, 43 logs: logReducer, 44 watch: watchReducer, 45 console: consoleReducer, 46 addBucket: addBucketsReducer, 47 bucketDetails: bucketDetailsReducer, 48 objectBrowser: objectBrowserReducer, 49 healthInfo: healthInfoReducer, 50 dashboard: dashboardReducer, 51 register: registerReducer, 52 createUser: createUserReducer, 53 license: licenseReducer, 54 destination: destinationSlice, 55 }); 56 57 export const store = configureStore({ 58 reducer: rootReducer, 59 middleware: (getDefaultMiddleware) => 60 getDefaultMiddleware().concat(objectBrowserWSMiddleware(objectsWS)), 61 }); 62 63 if (process.env.NODE_ENV !== "production" && module.hot) { 64 module.hot.accept(() => { 65 store.replaceReducer(rootReducer); 66 }); 67 } 68 69 export type AppState = ReturnType<typeof rootReducer>; 70 71 export type AppDispatch = typeof store.dispatch; 72 export type RootState = ReturnType<typeof store.getState>; 73 export const useAppDispatch = () => useDispatch<AppDispatch>(); 74 export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector; 75 76 export default store;