Created
November 4, 2025 23:18
-
-
Save tanat/c68aebf593c5b009f260f5d58e794deb to your computer and use it in GitHub Desktop.
store/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { configureStore, combineReducers } from '@reduxjs/toolkit'; | |
| import { persistStore, persistReducer } from 'redux-persist'; | |
| import storage from 'redux-persist/lib/storage'; | |
| // Entity reducers (state management only) | |
| import { userReducer } from '@entities/user'; | |
| import { gameReducer, gameApi as gameEntityApi } from '@entities/game'; | |
| import { contestApi } from '@entities/contest'; | |
| import { authApi } from '@features/auth'; | |
| import { gameActionsApi } from '@features/game-actions'; | |
| import { paymentApi } from '@features/payment-flow'; | |
| import { prizeApi } from '@shared/api/services'; | |
| import { preloaderReducer } from '@shared/model'; | |
| // Persist config | |
| const persistConfig = { | |
| key: 'root', | |
| storage, | |
| whitelist: ['user'], // Only persist user state | |
| }; | |
| // Root reducer | |
| const rootReducer = combineReducers({ | |
| user: userReducer, | |
| game: gameReducer, | |
| preloader: preloaderReducer, | |
| [authApi.reducerPath]: authApi.reducer, | |
| [gameEntityApi.reducerPath]: gameEntityApi.reducer, | |
| [gameActionsApi.reducerPath]: gameActionsApi.reducer, | |
| [contestApi.reducerPath]: contestApi.reducer, | |
| [prizeApi.reducerPath]: prizeApi.reducer, | |
| [paymentApi.reducerPath]: paymentApi.reducer, | |
| }); | |
| const persistedReducer = persistReducer(persistConfig, rootReducer); | |
| export const createStore = (options?: any) => | |
| configureStore({ | |
| reducer: persistedReducer, | |
| middleware: (getDefaultMiddleware) => | |
| getDefaultMiddleware({ | |
| serializableCheck: { | |
| ignoredActions: ['persist/PERSIST', 'persist/REHYDRATE'], | |
| }, | |
| }).concat( | |
| authApi.middleware, | |
| gameEntityApi.middleware, | |
| gameActionsApi.middleware, | |
| contestApi.middleware, | |
| prizeApi.middleware, | |
| paymentApi.middleware | |
| ), | |
| ...options, | |
| }); | |
| export const store = createStore(); | |
| export const persistor = persistStore(store); | |
| // Infer the `RootState` and `AppDispatch` types from the store itself | |
| export type RootState = ReturnType<typeof rootReducer>; | |
| export type AppDispatch = typeof store.dispatch; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment