Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (this == null || this.data == null) {
console.warn('请绑定diff函数到Page/Component实例!');
return false;
};
// filter data without __webviewId__ from this.data
let oldData = Object.keys(newData).reduce((prev, key)=>{
if (key === '__webviewId__') return prev;
if (this.data.hasOwnProperty(key)) {
prev[key] = this.data[key];
};
return prev;
}, {});
let diffValue = diff(oldData, newData);
return flatten(oldData, newData, diffValue);
}
export function normalizedDiff(existingPost, newPost) {
let existingObject = normalizePost(existingPost);
let newObject = normalizePost(newPost);
// handle the fact that images are updated via OG scraping, so we only care if more became available
newObject.images = Object.assign(existingObject.images, newObject.images);
let objectDiff = diff(existingObject, newObject);
// remove the immutable fields from the diff
for (let f of immutableFields) {
delete objectDiff[f];
}
return Object.keys(objectDiff);
}
private static difference(prev: object | null, next: object) {
if (prev != null) {
const difference = diff(prev, next);
if (!Bucket.isEmpty(difference)) {
console.log(difference)
}
} else {
console.info(next);
}
}
generate() {
global.reduxReport.__inProgress = true
const used = JSON.parse(JSON.stringify(this.accessedState))
const stateCopy = JSON.parse(JSON.stringify(this.state))
const unused = diff(stateCopy, used)
replaceUndefinedWithNull(unused)
const report = {
used,
unused,
stateCopy
}
global.reduxReport.__inProgress = false
return report
}
}
async function installDiff(oldPkgJson: PkgJson, newPkgJson: PkgJson): Promise {
const logger = getLogger();
const allDepsOld = Object.assign({}, oldPkgJson.devDependencies, oldPkgJson.dependencies);
const allDepsNew = Object.assign({}, newPkgJson.devDependencies, newPkgJson.dependencies);
const depsDiff = objectDiff.diff(allDepsOld, allDepsNew);
const depsToInstall = _.omitBy(depsDiff, _.isUndefined);
const depsToUninstall = _.keys(_.pickBy(depsDiff, _.isUndefined));
const loggingDepsToInstall = 'Installing dependencies: ' +
Object.keys(depsToInstall).map(pkg => `${pkg}@${depsToInstall[pkg]}`).join(' ');
const loggingDepsToUninstall = 'Uninstalling dependencies: ' + depsToUninstall.join(' ');
if (_.keys(depsToInstall).length) {
logger.info(loggingDepsToInstall);
await npmWrapper.install(depsToInstall);
}
if (depsToUninstall.length) {
logger.info(loggingDepsToUninstall);
return new Promise((resolve, reject) => {
const logger = getLogger();
const allDepsOld = Object.assign({}, oldPkgJson.devDependencies, oldPkgJson.dependencies);
const allDepsNew = Object.assign({}, newPkgJson.devDependencies, newPkgJson.dependencies);
const depsDiff = objectDiff.diff(allDepsOld, allDepsNew);
const depsToInstall = _.omitBy(depsDiff, _.isUndefined);
const depsToUninstall = _.keys(_.pickBy(depsDiff, _.isUndefined));
const loggingDepsToInstall = 'Installing dependencies: ' +
Object.keys(depsToInstall).map(pkg => `${pkg}@${depsToInstall[pkg]}`).join(' ');
const loggingDepsToUninstall = 'Uninstalling dependencies: ' + depsToUninstall.join(' ');
if (_.keys(depsToInstall).length) {
logger.info(loggingDepsToInstall);
return npmWrapper.install(depsToInstall)
.then(() => {
if (depsToUninstall.length) {
logger.info(loggingDepsToUninstall);
return npmWrapper.uninstall(depsToUninstall).then(resolve, reject);
onGUIConfigUpdate(configOutput) {
const normalizedConfig = this.normalizeConfig(configOutput);
const configDiff = deepDiff.diff(normalizedConfig, this.config);
if (Object.keys(configDiff).length) {
const newConfigSet = this.setConfig(configOutput);
if (newConfigSet.success) {
this.processAll();
const jsonStr = JSON.stringify(configOutput, null, 2);
fse.outputFile(this.configFile, jsonStr, err => {
this.configFileWritten = true;
if (err) {
gui.updateFinish();
this.eventsHandler.dispatch(
'error',
'Unable to save config file from GUI update'