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);
}
diffProfiles (oldProfile, newProfile) {
// This method will return added or modified entries.
let diff = detailedDiff(oldProfile, newProfile)
return Object.assign(diff.added, diff.updated)
}
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);
}
}
store.subscribe ( () => {
const date = new Date (),
timestamp = `[${padLeft ( date.getHours (), 2, 0 )}:${padLeft ( date.getMinutes (), 2, 0 )}:${padLeft ( date.getSeconds (), 2, 0 )}.${padLeft ( date.getMilliseconds (), 3, 0 )}]`;
group ( `${name} ${timestamp}` );
const {state} = store;
if ( options.logStateDiffChanges ) {
const {detailedDiff} = require ( 'deep-object-diff' ),
{added, updated, deleted} = detailedDiff ( prevState, state ) as any; //TSC
if ( !isEmptyObject ( added ) ) {
console.log ( 'Added\n ', added );
}
if ( !isEmptyObject ( updated ) ) {
console.log ( 'Updated\n ', updated );
}
if ( !isEmptyObject ( deleted ) ) {
console.log ( 'Deleted\n ', deleted );
}
}
if ( options.logStateFullChanges && !areShallowEqual ( state, prevState ) ) {
export default async (ctx, next) => {
const { namespace, getState } = ctx.store;
const { name: actionName } = ctx.action;
const preState = clone(getState());
const value = await next();
const state = clone(getState());
const diff: any = detailedDiff(preState, state);
const hasChanges = obj => Object.keys(obj).length > 0;
console.group('Store Name: ', namespace);
console.log('Action Name: ', actionName);
if (hasChanges(diff.added)) {
console.log('Added\n', diff.added);
}
if (hasChanges(diff.updated)) {
console.log('Updated\n', diff.updated);
}
if (hasChanges(diff.deleted)) {
console.log('Deleted\n', diff.deleted);
}
container.subscribe(() => {
if (!(UNSTATED.isEnabled && UNSTATED.logStateChanges)) {
return;
}
const {state} = container;
const diff = detailedDiff(prevState, state);
const group = UNSTATED.isCollapsed ? console.groupCollapsed : console.group;
group(name);
const hasChanges = obj => Object.keys(obj).length > 0;
if (hasChanges(diff.added)) {
console.log('Added\n', diff.added);
}
if (hasChanges(diff.updated)) {
console.log('Updated\n', diff.updated);
}
if (hasChanges(diff.deleted)) {
console.log('Deleted\n', diff.deleted);
if (alreadyExist) {
if (!confirm('This seal identity already exists.\n'
+ 'Do you still want to update it?')) {
this.formLocked = false;
return;
}
}
promise = this.service.update(this.user.id, cleaned)
.then((up) => this.submitSucceed.emit(up));
} else {
user.createDefaultKey = this.createDefaultKey;
if (this.sendPasswordEmail) {
user.password = null;
}
const cleaned: any = addedDiff({}, cleanupObject(user));
const alreadyExist = await this.checkSealIdentity(user);
if (alreadyExist) {
if (!confirm('This seal identity already exists.\n'
+ 'Do you still want to create it?')) {
this.formLocked = false;
return;
}
}
promise = this.service.create(cleaned)
.then((up) => {
if (this.sendPasswordEmail) {
try {
this.sendResetPasswordEmail(up);
} catch (err) {
log.debug(err);
await client.setMessengerProfile(omit(_profile, 'whitelistedDomains'));
} else {
await client.setMessengerProfile(_profile);
}
print(`Successfully set ${bold('messenger_profile')} settings`);
} else {
const [_existedProfile] = await client.getMessengerProfile(FIELDS);
const profile = trimDomain(_profile);
const existedProfile = trimDomain(_existedProfile);
const diffResult = diff(existedProfile, profile);
if (Object.keys(diffResult).length !== 0) {
const shouldDeleteFields = Object.keys(
deletedDiff(existedProfile, profile)
);
const shouldSetFields = [
...Object.keys(addedDiff(existedProfile, profile)),
...Object.keys(updatedDiff(existedProfile, profile)),
];
if (shouldDeleteFields.length > 0) {
await client.deleteMessengerProfile(
shouldDeleteFields.map(field => snakecase(field))
);
const deleteFileds = shouldDeleteFields.join(', ');
print(`Successfully delete ${bold(deleteFileds)} settings`);
}
if (shouldSetFields.length > 0) {
async submit() {
this.formLocked = true;
const user = this.form.value;
user.phone = this.tmpPhone;
user.countryCallingCode = this.tmpCountryCallingCode;
user.mode = this.userMode;
this.helper = null;
let promise;
if (this.mode === 'edit') {
const cleaned: ApiPutUserObject = updatedDiff(Object.assign({ password: undefined }, this.user), replaceInObject(user, '', null));
const alreadyExist = cleaned.identity && (cleaned.identity.commonName || cleaned.identity.organization)
? await this.checkSealIdentity(user) : false;
if (alreadyExist) {
if (!confirm('This seal identity already exists.\n'
+ 'Do you still want to update it?')) {
this.formLocked = false;
return;
}
}
promise = this.service.update(this.user.id, cleaned)
.then((up) => this.submitSucceed.emit(up));
} else {
user.createDefaultKey = this.createDefaultKey;
if (this.sendPasswordEmail) {
user.password = null;