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(() => { useEffect(() => {
if (serialConnection.portController !== null && serialConnection.portController !== undefined) { if (serialConnection.portController !== null) {
serialConnection.portController.parser.on("data", SerialDataListener); serialConnection.portController.parser.on("data", SerialDataListener);
} }
return () => { return () => {
if (serialConnection.portController !== null && serialConnection.portController !== undefined) { if (serialConnection.portController !== null) {
serialConnection.portController.parser.removeListener("data", SerialDataListener); serialConnection.portController.parser.removeListener("data", SerialDataListener);
} }
}; };
}, [serialConnection]); }, [serialConnection]);
const sendIncreaseHandler = (index: number) => { 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`); serialConnection.portController.port.write(`${index}i`);
} }
}; };
const sendDecreaseHandler = (index: number) => { 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`); serialConnection.portController.port.write(`${index}d`);
} }
}; };
const sendToggleHandler = (index: number) => { 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`); serialConnection.portController.port.write(`${index}t`);
} }
}; };

View file

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