WebStudio/src/store.ts
Marks Polakovs daeacd238f Add state persistence
Currently it's limited to the "options" key but can be expanded
2020-04-10 10:04:42 +02:00

32 lines
957 B
TypeScript

import rootReducer, { RootState } from "./rootReducer";
import { configureStore, Action, getDefaultMiddleware } from "@reduxjs/toolkit";
import { ThunkAction } from "redux-thunk";
import {
mixerMiddleware,
mixerKeyboardShortcutsMiddleware,
} from "./mixer/state";
import { tabSyncMiddleware } from "./optionsMenu/state";
import { persistStore } from "redux-persist";
const store = configureStore({
reducer: rootReducer,
middleware: [
mixerMiddleware,
mixerKeyboardShortcutsMiddleware,
tabSyncMiddleware,
...getDefaultMiddleware(),
],
});
if (process.env.NODE_ENV === "development" && module.hot) {
module.hot.accept("./rootReducer", () => {
const newRootReducer = require("./rootReducer").default;
store.replaceReducer(newRootReducer);
});
}
export const persistor = persistStore(store);
export type AppDispatch = typeof store.dispatch;
export type AppThunk = ThunkAction<void, RootState, null, Action<string>>;
export default store;