Skip to content

Commit

Permalink
optimize a lil
Browse files Browse the repository at this point in the history
  • Loading branch information
JovannMC committed Jan 20, 2025
1 parent 201606c commit 62186ca
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"@electron/rebuild": "^3.7.1",
"@types/lodash-es": "^4.17.12",
"@types/node": "^22.10.7",
"@types/serialport": "^10.2.0",
"@types/three": "^0.172.0",
"bulma": "^1.0.3",
"copyfiles": "^2.4.1",
Expand Down
6 changes: 3 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1106,13 +1106,13 @@ ipcMain.on("save-setting", (_event, data) => {
saveSetting(data);
});

import * as _ from "lodash-es";
import mergeWith from "lodash-es/mergeWith.js";
function saveSetting(data: { [key: string]: any }) {
const config: { [key: string]: any } = JSON.parse(fs.readFileSync(configPath).toString());

// Use lodash's mergeWith() to merge the new data with the existing config (not merge() as it doesn't remove old keys if purposely removed by program, e.g. comPorts)
const mergedConfig = _.mergeWith(config, data, (objValue: any, srcValue: any) => {
if (_.isArray(objValue)) {
const mergedConfig = mergeWith(config, data, (objValue: any, srcValue: any) => {
if (Array.isArray(objValue)) {
return srcValue;
}
});
Expand Down

0 comments on commit 62186ca

Please sign in to comment.