WebStudio/src/rootReducer.ts

59 lines
1.6 KiB
TypeScript
Raw Normal View History

2019-11-26 10:01:26 +00:00
import { combineReducers } from "@reduxjs/toolkit";
2021-06-02 19:27:23 +00:00
import {
persistReducer,
PersistConfig,
createMigrate,
PersistedState,
} from "redux-persist";
import webStorage from "redux-persist/lib/storage";
import autoMergeLevel2 from "redux-persist/lib/stateReconciler/autoMergeLevel2";
2019-11-26 10:01:26 +00:00
import ShowplanReducer from "./showplanner/state";
2020-03-19 17:49:55 +00:00
import MixerReducer from "./mixer/state";
2021-05-31 19:57:11 +00:00
import BroadcastReducer from "./broadcast/state";
import sessionReducer from "./session/state";
2021-05-31 20:42:48 +00:00
import NavbarReducer from "./navbar/state";
2021-05-31 19:57:11 +00:00
import OptionsMenuReducer from "./optionsMenu/state";
import SettingsState from "./optionsMenu/settingsState";
2021-06-02 19:27:23 +00:00
import produce from "immer";
2019-11-26 10:01:26 +00:00
2021-05-31 19:57:11 +00:00
import BAPSSessionReducer from "./bapsiclesession/state";
2019-11-26 10:01:26 +00:00
const rootReducer = combineReducers({
2020-04-19 13:47:19 +00:00
showplan: ShowplanReducer,
mixer: MixerReducer,
2021-05-31 19:57:11 +00:00
broadcast: BroadcastReducer,
2020-04-19 13:47:19 +00:00
session: sessionReducer,
navbar: NavbarReducer,
2021-05-31 19:57:11 +00:00
optionsMenu: OptionsMenuReducer,
settings: SettingsState,
bapsSession: BAPSSessionReducer,
2019-11-26 10:01:26 +00:00
});
2021-06-02 19:27:23 +00:00
const persistMigrations = createMigrate({
0: (state) =>
produce(
state,
(x: PersistedState & Pick<_InternalRootState, "settings">) => {
x.settings.saveShowPlanChanges = true;
}
),
});
type _InternalRootState = ReturnType<typeof rootReducer>;
2019-11-26 10:01:26 +00:00
2021-06-02 19:27:23 +00:00
const persistenceConfig: PersistConfig<_InternalRootState> = {
2020-04-19 13:47:19 +00:00
key: "root",
storage: webStorage,
whitelist: ["settings"],
2020-04-19 16:33:34 +00:00
stateReconciler: autoMergeLevel2,
2021-06-02 19:27:23 +00:00
version: 0,
migrate: persistMigrations,
};
const persistedReducer = persistReducer(persistenceConfig, rootReducer);
2021-06-02 19:27:23 +00:00
export type RootState = ReturnType<typeof persistedReducer>;
export default persistedReducer;