1 import type { TypedStartListening } from '@reduxjs/toolkit';
2 import { configureStore, createListenerMiddleware } from '@reduxjs/toolkit';
4 import { getPersistedState } from '@proton/redux-shared-store/persist';
5 import { ignoredActions, ignoredPaths } from '@proton/redux-shared-store/sharedSerializable';
7 import { start } from './listener';
8 import { type CalendarState, persistReducer, rootReducer } from './rootReducer';
9 import { type CalendarThunkArguments, extraThunkArguments } from './thunk';
11 export type { CalendarState };
13 export const setupStore = ({
17 preloadedState?: Partial<CalendarState>;
20 const listenerMiddleware = createListenerMiddleware({ extra: extraThunkArguments });
22 const store = configureStore({
25 devTools: process.env.NODE_ENV !== 'production',
26 middleware: (getDefaultMiddleware) =>
27 getDefaultMiddleware({
29 ignoredActions: [...ignoredActions],
30 ignoredPaths: [...ignoredPaths],
32 thunk: { extraArgument: extraThunkArguments },
33 }).prepend(listenerMiddleware.middleware),
36 const startListening = listenerMiddleware.startListening as AppStartListening;
37 const getCalendarPersistedState = persist
38 ? (state: CalendarState) => getPersistedState(state, persistReducer)
40 start({ startListening, persistTransformer: getCalendarPersistedState });
42 if (process.env.NODE_ENV !== 'production' && module.hot) {
43 module.hot.accept('./rootReducer', () => store.replaceReducer(rootReducer));
44 module.hot.accept('./listener', () => {
45 listenerMiddleware.clearListeners();
46 start({ startListening, persistTransformer: getCalendarPersistedState });
50 return Object.assign(store, {
52 listenerMiddleware.clearListeners();
57 export const extendStore = (newThunkArguments: Partial<CalendarThunkArguments>) => {
58 Object.assign(extraThunkArguments, newThunkArguments);
61 export type CalendarStore = ReturnType<typeof setupStore>;
62 export type CalendarDispatch = CalendarStore['dispatch'];
63 type ExtraArgument = typeof extraThunkArguments;
64 export type CalendarThunkExtra = {
66 dispatch: CalendarDispatch;
70 export type AppStartListening = TypedStartListening<CalendarState, CalendarDispatch, ExtraArgument>;