Skip to content

Commit ae9b5e4

Browse files
fix(client): use same store in dev and prod (freeCodeCamp#63521)
1 parent 067110d commit ae9b5e4

File tree

1 file changed

+13
-45
lines changed

1 file changed

+13
-45
lines changed

client/src/redux/create-store.ts

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
import { createStore as reduxCreateStore, applyMiddleware } from 'redux';
2-
// import { composeWithDevTools } from '@redux-devtools/extension';
31
import { createEpicMiddleware } from 'redux-observable';
42
import createSagaMiddleware from 'redux-saga';
53
import { configureStore } from '@reduxjs/toolkit';
64

7-
import envData from '../../config/env.json';
85
import { isBrowser } from '../../utils';
96
import {
107
examAttempts,
@@ -20,8 +17,6 @@ declare const module: {
2017
};
2118
};
2219

23-
const { environment } = envData;
24-
2520
const clientSide = isBrowser();
2621

2722
const sagaMiddleware = createSagaMiddleware({
@@ -37,47 +32,20 @@ const epicMiddleware = createEpicMiddleware({
3732
}
3833
});
3934

40-
// const composeEnhancers = composeWithDevTools({
41-
// // options like actionSanitizer, stateSanitizer
42-
// });
43-
4435
export const createStore = (preloadedState = {}) => {
45-
let store;
46-
if (environment === 'production') {
47-
store = reduxCreateStore(
48-
rootReducer,
49-
preloadedState,
50-
applyMiddleware(
51-
sagaMiddleware,
52-
epicMiddleware,
53-
// @ts-expect-error RTK uses unknown, Redux uses any
54-
examAttempts.middleware,
55-
examEnvironmentAuthorizationTokenApi.middleware
56-
)
57-
);
58-
} else {
59-
// store = reduxCreateStore(
60-
// rootReducer,
61-
// preloadedState,
62-
// composeEnhancers(
63-
// // @ts-expect-error RTK uses unknown, Redux uses any
64-
// applyMiddleware(sagaMiddleware, epicMiddleware, examAttempts.middleware)
65-
// )
66-
// );
67-
store = configureStore({
68-
// @ts-expect-error RTK uses unknown, Redux uses any
69-
reducer: rootReducer,
70-
// @ts-expect-error RTK uses unknown, Redux uses any
71-
middleware: getDefaultMiddleware => {
72-
return getDefaultMiddleware()
73-
.concat(examAttempts.middleware)
74-
.concat(examEnvironmentAuthorizationTokenApi.middleware)
75-
.concat(sagaMiddleware)
76-
.concat(epicMiddleware);
77-
},
78-
preloadedState
79-
});
80-
}
36+
const store = configureStore({
37+
// @ts-expect-error RTK uses unknown, Redux uses any
38+
reducer: rootReducer,
39+
// @ts-expect-error RTK uses unknown, Redux uses any
40+
middleware: getDefaultMiddleware => {
41+
return getDefaultMiddleware()
42+
.concat(examAttempts.middleware)
43+
.concat(examEnvironmentAuthorizationTokenApi.middleware)
44+
.concat(sagaMiddleware)
45+
.concat(epicMiddleware);
46+
},
47+
preloadedState
48+
});
8149
sagaMiddleware.run(rootSaga);
8250
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
8351
epicMiddleware.run(rootEpic);

0 commit comments

Comments
 (0)