Browse Source
1. 系统代理中的排除列表,可配置化;可在界面中配置,也可在远程配置中配置 # 问题修复: 1. 空指针异常导致插件关闭失败的问题修复 2. 偶发的空指针异常导致代理请求失败,原因不明,暂时规避掉 # 配置调整: 1. 添加几项targets配置,优化1项配置 2. 添加几项拦截配置 3. 添加很多项系统代理排除项,并调整白名单配置 4. 优化dns配置 5. `.gitignore` 中,排除掉 `package-lock.json` # 功能优化: 1. 远程配置内容格式不正确时,不保存它 2. 部分日志优化 3. 封装 merge.js 的 doDiff 和 doMarge 两个方法,方便使用和测试,同时添加测试用例 `mergeTest.js`,删除老的 `mergeTest.mjs`;doDiff优化过,使 config.json5 的内容更准确的体现用户自定义配置 4. 打开链接的方法,全部改为异步 # 文档: 1. 移除部分 `gitee仓库` 相关的内容,因为gitee的仓库被禁了,部分gitee地址改为github地址 2. 代码贡献说明中,添加环境准备相关说明;同时添加4个bat脚本文件方便windows用户快速贡献代码pull/274/head
王良
9 months ago
28 changed files with 562 additions and 7360 deletions
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,87 @@
|
||||
const lodash = require('lodash') |
||||
|
||||
/** |
||||
* 找出 newObj 相对于 oldObj 有差异的部分 |
||||
* |
||||
* @param oldObj |
||||
* @param newObj |
||||
* @returns {{}|*} |
||||
*/ |
||||
function doDiff (oldObj, newObj) { |
||||
if (newObj == null) { |
||||
return oldObj |
||||
} |
||||
|
||||
// 临时的对象,用于找出被删除的数据
|
||||
const tempObj = { ...oldObj } |
||||
// 删除空项,使差异对象更干净一些,体现出用户自定义内容
|
||||
deleteNullItems(tempObj) |
||||
|
||||
// 保存差异的对象
|
||||
const diffObj = {} |
||||
|
||||
// 读取新对象,并解析
|
||||
for (const key in newObj) { |
||||
const newValue = newObj[key] |
||||
const oldValue = oldObj[key] |
||||
|
||||
// 新值不为空,旧值为空时,直接取新值
|
||||
if (newValue != null && oldValue == null) { |
||||
diffObj[key] = newValue |
||||
continue |
||||
} |
||||
// 新旧值相等时,忽略
|
||||
if (lodash.isEqual(newValue, oldValue)) { |
||||
delete tempObj[key] |
||||
continue |
||||
} |
||||
// 新的值为数组时,直接取新值
|
||||
if (lodash.isArray(newValue)) { |
||||
diffObj[key] = newValue |
||||
delete tempObj[key] |
||||
continue |
||||
} |
||||
|
||||
// 新的值为对象时,递归合并
|
||||
if (lodash.isObject(newValue)) { |
||||
diffObj[key] = doDiff(oldValue, newValue) |
||||
delete tempObj[key] |
||||
continue |
||||
} |
||||
|
||||
// 基础类型,直接覆盖
|
||||
delete tempObj[key] |
||||
diffObj[key] = newValue |
||||
} |
||||
|
||||
// tempObj 里面剩下的是被删掉的数据
|
||||
lodash.forEach(tempObj, (oldValue, key) => { |
||||
// 将被删除的属性设置为null,目的是为了merge时,将被删掉的对象设置为null,达到删除的目的
|
||||
diffObj[key] = null |
||||
}) |
||||
|
||||
return diffObj |
||||
} |
||||
|
||||
function deleteNullItems (target) { |
||||
lodash.forEach(target, (item, key) => { |
||||
if (item == null) { |
||||
delete target[key] |
||||
} |
||||
if (lodash.isObject(item)) { |
||||
deleteNullItems(item) |
||||
} |
||||
}) |
||||
} |
||||
|
||||
module.exports = { |
||||
doMerge: function (oldObj, newObj) { |
||||
return lodash.mergeWith(oldObj, newObj, function (objValue, srcValue) { |
||||
if (lodash.isArray(objValue)) { |
||||
return srcValue |
||||
} |
||||
}) |
||||
}, |
||||
doDiff, |
||||
deleteNullItems |
||||
} |
@ -0,0 +1,88 @@
|
||||
const lodash = require('lodash') |
||||
const mergeApi = require('../src/merge.js') |
||||
|
||||
// 默认配置
|
||||
const defConfig = { |
||||
a: { |
||||
aa: { value: 1 }, |
||||
bb: { value: 2 } |
||||
}, |
||||
b: { c: 2 }, |
||||
c: 1, |
||||
d: [1, 2, 3], |
||||
e: { |
||||
aa: 2, |
||||
ee: 5 |
||||
}, |
||||
f: { |
||||
x: 1 |
||||
}, |
||||
g: [1, 2], |
||||
h: null, |
||||
i: null |
||||
} |
||||
|
||||
// 自定义配置
|
||||
const customConfig = { |
||||
a: { |
||||
bb: { value: 2 }, |
||||
cc: { value: 3 } |
||||
}, |
||||
b: { c: 2 }, |
||||
c: null, |
||||
d: [1, 2, 3, 4], |
||||
e: { |
||||
aa: 2, |
||||
ee: 5, |
||||
ff: 6 |
||||
}, |
||||
f: {}, |
||||
g: [1, 2], |
||||
h: null |
||||
} |
||||
|
||||
// doDiff
|
||||
const doDiffResult = mergeApi.doDiff(defConfig, customConfig) |
||||
console.log('doDiffResult:', JSON.stringify(doDiffResult, null, 2)) |
||||
console.log('\r') |
||||
// 校验doDiff结果
|
||||
const doDiffExpect = { |
||||
a: { |
||||
aa: null, |
||||
cc: { value: 3 } |
||||
}, |
||||
c: null, |
||||
d: [1, 2, 3, 4], |
||||
e: { |
||||
ff: 6 |
||||
}, |
||||
f: { |
||||
x: null |
||||
} |
||||
} |
||||
console.log('check diff result:', lodash.isEqual(doDiffResult, doDiffExpect)) |
||||
console.log('\r') |
||||
|
||||
// doMerge
|
||||
const doMergeResult = mergeApi.doMerge(defConfig, doDiffResult) |
||||
// delete null item
|
||||
mergeApi.deleteNullItems(doMergeResult) |
||||
console.log('running:', JSON.stringify(doMergeResult, null, 2)) |
||||
// 校验doMerge结果
|
||||
const doMergeExpect = { |
||||
a: { |
||||
bb: { value: 2 }, |
||||
cc: { value: 3 } |
||||
}, |
||||
b: { c: 2 }, |
||||
d: [1, 2, 3, 4], |
||||
e: { |
||||
aa: 2, |
||||
ee: 5, |
||||
ff: 6 |
||||
}, |
||||
f: {}, |
||||
g: [1, 2] |
||||
} |
||||
console.log('check merge result:', lodash.isEqual(doMergeResult, doMergeExpect)) |
||||
console.log('\r') |
@ -0,0 +1,5 @@
|
||||
cd ../ |
||||
|
||||
npm install cnpm -g --registry=https://registry.npm.taobao.org |
||||
cnpm install lerna@6 -g |
||||
cnpm install phantomjs -g |
@ -0,0 +1,3 @@
|
||||
cd ../packages/gui |
||||
|
||||
npm run electron:build |
@ -1,57 +0,0 @@
|
||||
import lodash from "lodash"; |
||||
|
||||
const defConfig = {a:{aa:1,bb:2},b:{c:2},d:[1,2,3],e:{ee:1,aa:2}} |
||||
const newConfig = {a:{aa:1,bb:2},d:[5],e:{bb:2,ee:2,aa:2}} |
||||
|
||||
const result = { d: [ 5 ],e:{ee:2} } |
||||
|
||||
const load = {a:1,d:[5,1,2,3]} |
||||
const DELETE = '____DELETE____' |
||||
// lodash.mergeWith(defConfig,newConfig, (objValue, srcValue, key, object, source, stack) => {
|
||||
// console.log('stack', stack,'key',key)
|
||||
//
|
||||
// if (lodash.isArray(srcValue)) {
|
||||
// return srcValue
|
||||
// }
|
||||
// if(lodash.isEqual(objValue,srcValue)){
|
||||
// //如何删除
|
||||
// return DELETE
|
||||
// }
|
||||
// })
|
||||
|
||||
function doMerge (defObj, newObj) { |
||||
const defObj2 = { ...defObj } |
||||
const newObj2 = {} |
||||
lodash.forEach(newObj,(newValue,key)=>{ |
||||
// const newValue = newObj[key]
|
||||
const defValue = defObj[key] |
||||
if (lodash.isEqual(newValue, defValue)) { |
||||
delete defObj2[key] |
||||
return |
||||
} |
||||
|
||||
if (lodash.isArray(newValue)) { |
||||
delete defObj2[key] |
||||
newObj2[key] = newValue |
||||
return |
||||
} |
||||
if (lodash.isObject(newValue)) { |
||||
newObj2[key] = doMerge(defValue, newValue) |
||||
delete defObj2[key] |
||||
} else { |
||||
// 基础类型,直接覆盖
|
||||
delete defObj2[key] |
||||
newObj2[key] = newValue |
||||
} |
||||
}) |
||||
// defObj 里面剩下的是被删掉的
|
||||
lodash.forEach(defObj2, (defValue, key) => { |
||||
newObj2[key] = null |
||||
}) |
||||
return newObj2 |
||||
} |
||||
|
||||
console.log(doMerge(defConfig,newConfig)) |
||||
|
||||
|
||||
|
Loading…
Reference in new issue