How to use deep-object-diff - 10 common examples

To help you get started, we’ve selected a few deep-object-diff examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github wxajs / wxa / packages / wxa-core / src / diff / diff.js View on Github external
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);
}
github GetStream / Winds / api / src / utils / upsert.js View on Github external
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);
}
github amejia1 / atom-xterm / src / lib / atom-xterm-profiles.js View on Github external
diffProfiles (oldProfile, newProfile) {
    // This method will return added or modified entries.
    let diff = detailedDiff(oldProfile, newProfile)
    return Object.assign(diff.added, diff.updated)
  }
github yurafuca / nicosapo / src / javascripts / modules / Bucket.ts View on Github external
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);
        }
    }
github fabiospampinato / overstated / src / debug.ts View on Github external
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 ) ) {
github ice-lab / icestore / middlewares / logger / src / index.ts View on Github external
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);
  }
github sindresorhus / unstated-debug / index.js View on Github external
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);
github woleet / woleet.id-server / client / src / app / components / parts / user.form / index.ts View on Github external
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);
github Yoctol / bottender / packages / bottender / src / cli / providers / messenger / profile.ts View on Github external
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) {
github woleet / woleet.id-server / client / src / app / components / parts / user.form / index.ts View on Github external
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;

deep-object-diff

Deep diffs two objects, including nested structures of arrays and objects, and return the difference.

MIT
Latest version published 1 year ago

Package Health Score

67 / 100
Full package analysis