11import { merge } from 'lodash-es' ;
2- import { applyMiddleware , compose , createStore } from 'redux' ;
32import { useDispatch } from 'react-redux' ;
4- import thunk , { ThunkDispatch } from 'redux-thunk' ;
3+ import { configureStore as reduxConfigureStore } from '@reduxjs/toolkit' ;
4+ import { produce } from 'immer' ;
5+ import type { } from 'redux-thunk/extend-redux' ;
56
6- import { Action , initializeApplication } from './actions' ;
7+ import { initializeApplication } from './actions' ;
78import initializeLocalStorage from './local_storage' ;
89import initializeSessionStorage from './session_storage' ;
9- import playgroundApp , { State } from './reducers' ;
1010import { websocketMiddleware } from './websocketMiddleware' ;
11+ import reducer from './reducers' ;
1112
1213export default function configureStore ( window : Window ) {
1314 const baseUrl = new URL ( '/' , window . location . href ) . href ;
@@ -18,22 +19,23 @@ export default function configureStore(window: Window) {
1819 baseUrl,
1920 } ,
2021 } ;
21- const initialAppState = playgroundApp ( undefined , initializeApplication ( ) ) ;
22+ const initialAppState = reducer ( undefined , initializeApplication ( ) ) ;
2223
2324 const localStorage = initializeLocalStorage ( ) ;
2425 const sessionStorage = initializeSessionStorage ( ) ;
2526
26- const initialState = merge (
27+ const preloadedState = produce ( initialAppState , ( initialAppState ) => merge (
2728 initialAppState ,
2829 initialGlobalState ,
2930 localStorage . initialState ,
3031 sessionStorage . initialState ,
31- ) ;
32+ ) ) ;
3233
33- const middlewares = applyMiddleware < ThunkDispatch < State , { } , Action > , { } > ( thunk , websocket ) ;
34- const composeEnhancers : typeof compose = window . __REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose ;
35- const enhancers = composeEnhancers ( middlewares ) ;
36- const store = createStore ( playgroundApp , initialState , enhancers ) ;
34+ const store = reduxConfigureStore ( {
35+ reducer,
36+ preloadedState,
37+ middleware : ( getDefaultMiddleware ) => getDefaultMiddleware ( ) . concat ( websocket ) ,
38+ } )
3739
3840 store . subscribe ( ( ) => {
3941 const state = store . getState ( ) ;
0 commit comments