File size: 1,688 Bytes
e1d589b | 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 53 54 55 56 57 58 | import { configureStore, } from '@reduxjs/toolkit';
import questionApiReducer from 'ducks/questionApi';
import appReducer from 'ducks/app';
import questionApiService from "./services/questionApiService";
import appServices from "./services/appServices";
const getMiddleware = () => {
const services = {};
services.questionApiService = new questionApiService();
services.appServices = appServices;
return services;
};
const localStorageMiddleware = ({ getState }) => {
return next => action => {
const result = next(action);
const { app } = getState();
const toStore = { ...app, dialog: {
children: null,
open: false
}};
localStorage.setItem('gcaState', JSON.stringify(toStore));
return result;
};
};
const reHydrateStore = () => {
if (localStorage.getItem('gcaState') !== null) {
const app = JSON.parse(localStorage.getItem('gcaState'));
return {
app
}
}
};
export default configureStore({
reducer: {
questionApi: questionApiReducer,
app: appReducer
},
preloadedState: reHydrateStore(),
middleware: getDefaultMiddleware =>
getDefaultMiddleware({
thunk: {
extraArgument: getMiddleware()
},
serializableCheck: {
// Ignore these action types
ignoredActions: ['gca/questionApi/init/fulfilled','app/setDialog'],
ignoredActionPaths: ['payload.disable', 'payload.children.$$typeof', 'app.dialog.children.$$typeof']
}
}).concat(localStorageMiddleware),
devTools: true
});
|