-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstore.ts
52 lines (48 loc) · 1.94 KB
/
store.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
import { combineReducers, configureStore, Reducer } from '@reduxjs/toolkit';
import { setupListeners } from '@reduxjs/toolkit/query';
import { RESET_STATE_ACTION_TYPE } from './actions/resetState';
import { createLogger } from 'redux-logger';
import { persistStore } from 'redux-persist';
import { monitorReducerEnhancer } from './enchancers';
import { responseApi } from './detail/api';
import { birdApi } from './bird/api';
import birdslice from './bird/birdSlice';
const loggerMiddleware = createLogger();
const middlewares = [loggerMiddleware, responseApi.middleware, birdApi.middleware];
const reducers = {
[responseApi.reducerPath]: responseApi.reducer,
[birdApi.reducerPath]: birdApi.reducer,
[birdslice.reducerPath]: birdslice.reducer
};
const combinedReducer = combineReducers<typeof reducers>(reducers);
export const rootReducer: Reducer<RootState> = (state, action) => {
if (action.type === RESET_STATE_ACTION_TYPE) {
state = {} as RootState;
}
return combinedReducer(state, action);
};
export const store = configureStore({
reducer: rootReducer,
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware({
serializableCheck: false
// serializableCheck: {
// ignoredActions: [
// FLUSH,
// REHYDRATE,
// PAUSE,
// PERSIST,
// PURGE,
// REGISTER,
// // This action has functions set in store object so to avoid serializable check its been added here
// 'rtkWalletProvider/setRtkWalletProvider'
// ]
// }
}).concat(middlewares),
preloadedState: {},
enhancers: [monitorReducerEnhancer]
});
export type AppDispatch = typeof store.dispatch;
export type RootState = ReturnType<typeof combinedReducer>;
export const persistor = persistStore(store);
setupListeners(store.dispatch);