Add state persistence

Currently it's limited to the "options" key but can be expanded
This commit is contained in:
Marks Polakovs 2020-04-10 10:04:42 +02:00
parent 55f2ab8cb9
commit daeacd238f
4 changed files with 31 additions and 1 deletions

View file

@ -19,6 +19,7 @@
"@types/react-modal": "^3.10.5",
"@types/react-redux": "^7.1.5",
"@types/reactstrap": "^8.4.2",
"@types/redux-persist": "^4.3.1",
"@types/wavesurfer.js": "^3.2.0",
"@types/webpack-env": "^1.14.1",
"@typescript-eslint/eslint-plugin": "^2.2.0",
@ -76,6 +77,7 @@
"react-redux": "^7.1.3",
"reactstrap": "^8.4.1",
"redux": "^4.0.4",
"redux-persist": "^6.0.0",
"resolve": "1.12.0",
"resolve-url-loader": "3.1.0",
"sass-loader": "7.2.0",

View file

@ -1,5 +1,9 @@
import { combineReducers } from "@reduxjs/toolkit";
import { persistReducer, PersistConfig } from "redux-persist";
import webStorage from "redux-persist/lib/storage";
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
import ShowplanReducer from "./showplanner/state";
import MixerReducer from "./mixer/state";
import BroadcastReducer from "./broadcast/state";
@ -20,4 +24,13 @@ const rootReducer = combineReducers({
export type RootState = ReturnType<typeof rootReducer>;
export default rootReducer;
const persistenceConfig: PersistConfig<RootState> = {
key: "root",
storage: webStorage,
whitelist: ["settings"],
stateReconciler: autoMergeLevel2
};
const persistedReducer = persistReducer(persistenceConfig, rootReducer);
export default persistedReducer;

View file

@ -6,6 +6,7 @@ import {
mixerKeyboardShortcutsMiddleware,
} from "./mixer/state";
import { tabSyncMiddleware } from "./optionsMenu/state";
import { persistStore } from "redux-persist";
const store = configureStore({
reducer: rootReducer,
@ -24,6 +25,8 @@ if (process.env.NODE_ENV === "development" && module.hot) {
});
}
export const persistor = persistStore(store);
export type AppDispatch = typeof store.dispatch;
export type AppThunk = ThunkAction<void, RootState, null, Action<string>>;
export default store;

View file

@ -1531,6 +1531,13 @@
"@types/react" "*"
popper.js "^1.14.1"
"@types/redux-persist@^4.3.1":
version "4.3.1"
resolved "https://registry.yarnpkg.com/@types/redux-persist/-/redux-persist-4.3.1.tgz#aa4c876859e0bea5155e5f7980e5b8c4699dc2e6"
integrity sha1-qkyHaFngvqUVXl95gOW4xGmdwuY=
dependencies:
redux-persist "*"
"@types/resolve@0.0.8":
version "0.0.8"
resolved "https://registry.yarnpkg.com/@types/resolve/-/resolve-0.0.8.tgz#f26074d238e02659e323ce1a13d041eee280e194"
@ -9011,6 +9018,11 @@ redux-immutable-state-invariant@^2.1.0:
invariant "^2.1.0"
json-stringify-safe "^5.0.1"
redux-persist@*, redux-persist@^6.0.0:
version "6.0.0"
resolved "https://registry.yarnpkg.com/redux-persist/-/redux-persist-6.0.0.tgz#b4d2972f9859597c130d40d4b146fecdab51b3a8"
integrity sha512-71LLMbUq2r02ng2We9S215LtPu3fY0KgaGE0k8WRgl6RkqxtGfl7HUozz1Dftwsb0D/5mZ8dwAaPbtnzfvbEwQ==
redux-thunk@^2.3.0:
version "2.3.0"
resolved "https://registry.yarnpkg.com/redux-thunk/-/redux-thunk-2.3.0.tgz#51c2c19a185ed5187aaa9a2d08b666d0d6467622"