lodash#mergeWith JavaScript Examples

The following examples show how to use lodash#mergeWith. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: mergeRtvShapes.js    From lens-extension-cc with MIT License 6 votes vote down vote up
mergeRtvShapes = function (object, ...sources) {
  return mergeWith(
    object,
    ...[
      ...sources,
      (objValue, srcValue) => {
        if (Array.isArray(objValue)) {
          // if it's an Array, it's a typeset instead of a shape, and so we __overwrite__
          //  the current value with the source just like a non-Object property would
          //  since merging typesets is likely not the intent; we're just using Lodash
          //  merge() to merge shapes (Objects), not Arrays (RTV.js Typesets)
          return srcValue;
        }
      },
    ]
  );
}
Example #2
Source File: index.js    From datapass with GNU Affero General Public License v3.0 6 votes vote down vote up
function flattenDiffTransformer(accumulatorObject, fullObjectDiff, objectKey) {
  if (!isObject(fullObjectDiff[0])) {
    accumulatorObject[objectKey] = fullObjectDiff;

    return accumulatorObject;
  }
  // {contacts: [[{'name': 'c', email: 'd', work_email: 'a'}], [{'name': 'e', email: 'd'}]]}
  const objectBefore = flatten(fullObjectDiff[0], objectKey);
  const objectAfter = flatten(fullObjectDiff[1], objectKey);
  const objectDiff = mergeWith(
    objectBefore,
    objectAfter,
    (valueBefore, valueAfter) => [valueBefore, valueAfter]
  );
  // {0.name: ['c', 'e'], 0.email: ['d', 'd'], 0.work_email: 'a'}
  const objectDiffNoUnchangedNoDeprecated = omitBy(
    objectDiff,
    (value) => !isArray(value) || value[0] === value[1]
  );
  // {0.name: ['c', 'e']}
  const objectDiffPrefixedKey = mapKeys(
    objectDiffNoUnchangedNoDeprecated,
    (value, flatKey) => `${objectKey}.${flatKey}`
  );
  // {contacts.0.name: ['c', 'e']}
  Object.assign(accumulatorObject, objectDiffPrefixedKey);

  return accumulatorObject;
}
Example #3
Source File: Mappers.js    From sampo-ui with MIT License 5 votes vote down vote up
mergeObjects = (first, second) => {
  // Merge two objects into one object.
  return mergeWith(first, second, merger)
}