mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-25 02:14:11 -05:00
fix(client): use same store in dev and prod (#63521)
This commit is contained in:
@@ -1,10 +1,7 @@
|
||||
import { createStore as reduxCreateStore, applyMiddleware } from 'redux';
|
||||
// import { composeWithDevTools } from '@redux-devtools/extension';
|
||||
import { createEpicMiddleware } from 'redux-observable';
|
||||
import createSagaMiddleware from 'redux-saga';
|
||||
import { configureStore } from '@reduxjs/toolkit';
|
||||
|
||||
import envData from '../../config/env.json';
|
||||
import { isBrowser } from '../../utils';
|
||||
import {
|
||||
examAttempts,
|
||||
@@ -20,8 +17,6 @@ declare const module: {
|
||||
};
|
||||
};
|
||||
|
||||
const { environment } = envData;
|
||||
|
||||
const clientSide = isBrowser();
|
||||
|
||||
const sagaMiddleware = createSagaMiddleware({
|
||||
@@ -37,47 +32,20 @@ const epicMiddleware = createEpicMiddleware({
|
||||
}
|
||||
});
|
||||
|
||||
// const composeEnhancers = composeWithDevTools({
|
||||
// // options like actionSanitizer, stateSanitizer
|
||||
// });
|
||||
|
||||
export const createStore = (preloadedState = {}) => {
|
||||
let store;
|
||||
if (environment === 'production') {
|
||||
store = reduxCreateStore(
|
||||
rootReducer,
|
||||
preloadedState,
|
||||
applyMiddleware(
|
||||
sagaMiddleware,
|
||||
epicMiddleware,
|
||||
// @ts-expect-error RTK uses unknown, Redux uses any
|
||||
examAttempts.middleware,
|
||||
examEnvironmentAuthorizationTokenApi.middleware
|
||||
)
|
||||
);
|
||||
} else {
|
||||
// store = reduxCreateStore(
|
||||
// rootReducer,
|
||||
// preloadedState,
|
||||
// composeEnhancers(
|
||||
// // @ts-expect-error RTK uses unknown, Redux uses any
|
||||
// applyMiddleware(sagaMiddleware, epicMiddleware, examAttempts.middleware)
|
||||
// )
|
||||
// );
|
||||
store = configureStore({
|
||||
// @ts-expect-error RTK uses unknown, Redux uses any
|
||||
reducer: rootReducer,
|
||||
// @ts-expect-error RTK uses unknown, Redux uses any
|
||||
middleware: getDefaultMiddleware => {
|
||||
return getDefaultMiddleware()
|
||||
.concat(examAttempts.middleware)
|
||||
.concat(examEnvironmentAuthorizationTokenApi.middleware)
|
||||
.concat(sagaMiddleware)
|
||||
.concat(epicMiddleware);
|
||||
},
|
||||
preloadedState
|
||||
});
|
||||
}
|
||||
const store = configureStore({
|
||||
// @ts-expect-error RTK uses unknown, Redux uses any
|
||||
reducer: rootReducer,
|
||||
// @ts-expect-error RTK uses unknown, Redux uses any
|
||||
middleware: getDefaultMiddleware => {
|
||||
return getDefaultMiddleware()
|
||||
.concat(examAttempts.middleware)
|
||||
.concat(examEnvironmentAuthorizationTokenApi.middleware)
|
||||
.concat(sagaMiddleware)
|
||||
.concat(epicMiddleware);
|
||||
},
|
||||
preloadedState
|
||||
});
|
||||
sagaMiddleware.run(rootSaga);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
epicMiddleware.run(rootEpic);
|
||||
|
||||
Reference in New Issue
Block a user