How to use the deep-diff.applyChange function in deep-diff

To help you get started, we’ve selected a few deep-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 LiskHQ / lisk-sdk-examples / lisk / scripts / update_config.js View on Github external
if (changeInArrayElement) {
				_.set(
					customConfig,
					clonedPath,
					_.get(unifiedNewConfig, clonedPath, {})
				);
			} else if (changeInDeepObject) {
				// Remove last item in path to get index of object in array
				clonedPath.splice(-1, 1);
				_.set(
					customConfig,
					clonedPath,
					_.get(unifiedNewConfig, clonedPath, {})
				);
			}
			applyChange(customConfig, json, d);
		});
github LiskHQ / lisk-core / scripts / update_config.js View on Github external
if (changeInArrayElement) {
				_.set(
					customConfig,
					clonedPath,
					_.get(unifiedNewConfig, clonedPath, {})
				);
			} else if (changeInDeepObject) {
				// Remove last item in path to get index of object in array
				clonedPath.splice(-1, 1);
				_.set(
					customConfig,
					clonedPath,
					_.get(unifiedNewConfig, clonedPath, {})
				);
			}
			applyChange(customConfig, json, d);
		});
github F5Networks / f5-declarative-onboarding / src / lib / diffHandler.js View on Github external
observableDiff(from, to, (diff) => {
            // diff.path looks like ['Common', 'VLAN', 'myVlan'], for example
            if (this.classesOfTruth.indexOf(diff.path[1]) !== -1) {
                applyChange(from, to, diff);

                // the item at index 1 is the name of the class in the schema
                // if these are named objects (vlans, for example) the name is at
                // index 2
                const schemaClass = diff.path[1];
                let objectName;
                if (this.namelessClasses.indexOf(schemaClass) === -1) {
                    objectName = diff.path[2];
                }
                // For additions of named classes, the object name will be in the rhs object
                if (!objectName && diff.rhs) {
                    objectName = Object.keys(diff.rhs)[0];
                }

                if (updatedClasses.indexOf(schemaClass) === -1) {
                    updatedClasses.push(schemaClass);
github spring-raining / Giraf / src / stores / history.js View on Github external
redo() {
    const lastChange = this._revertStack.pop();
    if (lastChange) {
      for (let i = 0; i < lastChange.changes.length; i++) {
        let change = lastChange.changes[i];
        applyChange(change.target, true, change);
      }
      this._commitStack.push(lastChange);
    }
  }
github TheThingsNetwork / lorawan-stack / pkg / webui / lib / diff.js View on Github external
observableDiff(original, updated, function(d) {
    const entry = d.path[d.path.length - 1]
    if (!exclude.includes(entry)) {
      applyChange(result, undefined, d)
    }
  })
github ngneat / transloco / projects / ngneat / transloco-keys-manager / keysDetective.js View on Github external
if (!extracted) continue;
    /** Read the current file */
    const file = readFile(fileName);
    const fileObj = JSON.parse(file);
    const diffArr = DeepDiff(fileObj, extracted);
    if (diffArr) {
      const lang = `${scope || ''}${fileLang}`;
      result[lang] = {
        missing: [],
        extra: []
      };
      for (const diff of diffArr) {
        if (diff.kind === 'N') {
          result[lang].missing.push(diff);
          if (addMissing) {
            applyChange(fileObj, extracted, diff);
          }
        } else if (!_prodMode && diff.kind === 'D') {
          result[lang].extra.push(diff);
        }
      }
      if (addMissing) {
        const json = JSON.stringify(fileObj, null, 2);
        /** Write the corrected object to the original file */
        fs.writeFileSync(fileName, json, 'utf8');
      }
    }
  }
  if (_prodMode) {
    return;
  }
github exogen / graphql-markdown / src / diffSchema.js View on Github external
const diffSchema = changes.reduce((schema, change) => {
    diff.applyChange(schema, newDiffableSchema, change)
    return schema
  }, {})
  const schema = fromDiffableSchema(diffSchema)
github lukaszmakuch / rosmaro / src / dispatcher / ctx.js View on Github external
import deep from 'deep-diff';
const diff = deep.diff
const applyChange = deep.applyChange

export const mergeCtxs = (original, newOnes) => {
  if (newOnes.length == 1) return newOnes[0];
  
  let diffs = newOnes
    .map(c => diff(original, c))
    .reduce((flat, arr) => [].concat(flat, arr), [])
  let res = {...original};

  diffs
    .filter(a => a)
    .forEach(d => applyChange(res, true, d))

  return res
};

deep-diff

Javascript utility for calculating deep difference, capturing changes, and applying changes across objects; for nodejs and the browser.

MIT
Latest version published 6 years ago

Package Health Score

73 / 100
Full package analysis