Fix overwriting of blacklisted elements when refreshing

This commit is contained in:
GHOSCHT 2021-10-28 19:23:37 +02:00
parent 43725faea4
commit 5ccfe3753d
2 changed files with 8 additions and 17 deletions

View file

@ -21,29 +21,29 @@ const KnobSection = () => {
};
useEffect(() => {
if (serialConnection.portController !== null && serialConnection.portController !== undefined) {
if (serialConnection.portController !== null) {
serialConnection.portController.parser.on("data", SerialDataListener);
}
return () => {
if (serialConnection.portController !== null && serialConnection.portController !== undefined) {
if (serialConnection.portController !== null) {
serialConnection.portController.parser.removeListener("data", SerialDataListener);
}
};
}, [serialConnection]);
const sendIncreaseHandler = (index: number) => {
if (serialConnection.portController !== null && serialConnection.portController.port !== null && serialConnection.portController !== undefined) {
if (serialConnection.portController !== null && serialConnection.portController.port !== null) {
serialConnection.portController.port.write(`${index}i`);
}
};
const sendDecreaseHandler = (index: number) => {
if (serialConnection.portController !== null && serialConnection.portController.port !== null && serialConnection.portController !== undefined) {
if (serialConnection.portController !== null && serialConnection.portController.port !== null) {
serialConnection.portController.port.write(`${index}d`);
}
};
const sendToggleHandler = (index: number) => {
if (serialConnection.portController !== null && serialConnection.portController.port !== null && serialConnection.portController !== undefined) {
if (serialConnection.portController !== null && serialConnection.portController.port !== null) {
serialConnection.portController.port.write(`${index}t`);
}
};

View file

@ -1,11 +1,10 @@
import thunk from "redux-thunk";
import { createStore, applyMiddleware } from "redux";
import { RootAction, RootState } from "typesafe-actions";
import { persistStore, persistReducer, createTransform } from "redux-persist";
import { persistStore, persistReducer } from "redux-persist";
import createElectronStorage from "redux-persist-electron-storage";
import ElectronStore from "electron-store";
import omit from "lodash/omit";
import composeEnhancers from "./utils";
import rootReducer from "./root-reducer";
@ -19,20 +18,12 @@ createElectronStorage({
electronStore,
});
const blacklistPaths = ["serialConnection.portController", "serialConnection.status"];
const persistConfig = {
key: "root",
key: "serialConnection",
storage: createElectronStorage({
electronStore,
}),
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),
],
blacklist: ["portController"],
};
export const persistedReducer = persistReducer(persistConfig, rootReducer);