|
1 | | -import { createStore, applyMiddleware, compose } from 'redux'; |
2 | | -import thunk from 'redux-thunk'; |
| 1 | +import { configureStore } from '@reduxjs/toolkit'; |
| 2 | +import listenerMiddleware from './middleware'; |
3 | 3 | import DevTools from './modules/App/components/DevTools'; |
4 | 4 | import rootReducer from './reducers'; |
5 | 5 | import { clearState, loadState } from './persistState'; |
6 | 6 | import getConfig from './utils/getConfig'; |
7 | 7 |
|
8 | | -export default function configureStore(initialState) { |
9 | | - const enhancers = [applyMiddleware(thunk)]; |
10 | | - |
11 | | - if (getConfig('CLIENT') && getConfig('NODE_ENV') === 'development') { |
12 | | - // Enable DevTools only when rendering on client and during development. |
13 | | - enhancers.push( |
14 | | - window.devToolsExtension |
15 | | - ? window.devToolsExtension() |
16 | | - : DevTools.instrument() |
17 | | - ); |
18 | | - } |
| 8 | +// Enable DevTools only when rendering on client and during development. |
| 9 | +// Display the dock monitor only if no browser extension is found. |
| 10 | +export function showReduxDevTools() { |
| 11 | + return ( |
| 12 | + getConfig('CLIENT') && |
| 13 | + getConfig('NODE_ENV') === 'development' && |
| 14 | + !window.__REDUX_DEVTOOLS_EXTENSION__ |
| 15 | + ); |
| 16 | +} |
19 | 17 |
|
| 18 | +export default function setupStore(initialState) { |
20 | 19 | const savedState = loadState(); |
21 | 20 | clearState(); |
22 | 21 |
|
23 | | - const store = createStore( |
24 | | - rootReducer, |
25 | | - savedState != null ? savedState : initialState, |
26 | | - compose(...enhancers) |
27 | | - ); |
| 22 | + const store = configureStore({ |
| 23 | + reducer: rootReducer, |
| 24 | + middleware: (getDefaultMiddleware) => |
| 25 | + getDefaultMiddleware({ |
| 26 | + thunk: true, |
| 27 | + serializableCheck: true, |
| 28 | + // TODO: enable immutableCheck once the mutations are fixed. |
| 29 | + immutableCheck: false |
| 30 | + }).concat(listenerMiddleware.middleware), |
| 31 | + preloadedState: savedState || initialState, |
| 32 | + enhancers: showReduxDevTools() ? [DevTools.instrument()] : [] |
| 33 | + }); |
28 | 34 |
|
29 | 35 | if (module.hot) { |
30 | 36 | // Enable Webpack hot module replacement for reducers |
|
0 commit comments