This repository has been archived on 2023-12-22. You can view files and clone it, but cannot push or open issues or pull requests.
old-monorepo/Dashboard/src/redux/store/index.ts

48 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-08-27 00:26:40 +02:00
import thunk from "redux-thunk";
import { createStore, applyMiddleware } from "redux";
import { RootAction, RootState } from "typesafe-actions";
2021-10-28 18:55:56 +02:00
import { persistStore, persistReducer, createTransform } from "redux-persist";
2021-10-28 16:01:13 +02:00
import createElectronStorage from "redux-persist-electron-storage";
import ElectronStore from "electron-store";
2021-10-28 18:55:56 +02:00
import omit from "lodash/omit";
2021-08-27 00:26:40 +02:00
import composeEnhancers from "./utils";
import rootReducer from "./root-reducer";
const middlewares = [thunk];
const enhancer = composeEnhancers(applyMiddleware(...middlewares));
2021-10-28 18:55:56 +02:00
export const electronStore = new ElectronStore();
2021-10-28 16:01:13 +02:00
createElectronStorage({
electronStore,
});
2021-10-28 18:55:56 +02:00
const blacklistPaths = ["serialConnection.portController", "serialConnection.status"];
2021-10-28 16:01:13 +02:00
const persistConfig = {
key: "root",
storage: createElectronStorage({
electronStore,
}),
2021-10-28 18:55:56 +02:00
blacklist: blacklistPaths.filter((a) => !a.includes(".")),
transforms: [
// nested blacklist-paths require a custom transform to be applied
createTransform((inboundState: object, key) => {
const blacklistPathsForKey = blacklistPaths.filter((path) => path.startsWith(`${String(key)}.`)).map((path) => path.substr(String(key).length + 1));
return omit(inboundState, ...blacklistPathsForKey);
}, null),
],
2021-10-28 16:01:13 +02:00
};
export const persistedReducer = persistReducer(persistConfig, rootReducer);
2021-08-27 00:26:40 +02:00
const initialState = {};
2021-10-28 16:01:13 +02:00
export const store = createStore<RootState, RootAction, any, any>(
persistedReducer,
2021-08-27 00:26:40 +02:00
initialState,
enhancer,
);
2021-10-28 16:01:13 +02:00
export const persistor = persistStore(store);