lodash-es#mergeWith TypeScript Examples

The following examples show how to use lodash-es#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: mergeCustomize.tsx    From UUI with MIT License 6 votes vote down vote up
export function mergeCustomize<M extends string>(...customizes: Array<ComponentNodeCustomizeProps<M> | undefined>): ComponentNodeCustomizeProps<M> | undefined {
  const mergedCustomize: any = {}

  const customizer = (c1: IntrinsicNodeCustomizeProps | undefined, c2: IntrinsicNodeCustomizeProps) => {
    if (c1 === undefined) return c2

    const result = {
      ...c1,
      ...c2,
    }

    if (c1.extendClassName && c2.extendClassName) {
      result.extendClassName = classNames(c1.extendClassName, c2.extendClassName)
    }
    if (c1.extendStyle && c2.extendStyle) {
      result.extendStyle = { ...c1.extendStyle, ...c2.extendStyle }
    }
    if (c1.extendChildrenBefore && c2.extendChildrenBefore) {
      result.extendChildrenBefore = <>{c1.extendChildrenBefore}{c2.extendChildrenBefore}</>
    }
    if (c1.extendChildrenAfter && c2.extendChildrenAfter) {
      result.extendChildrenAfter = <>{c1.extendChildrenAfter}{c2.extendChildrenAfter}</>
    }

    return result
  }

  for (const customize of customizes) {
    mergeWith(mergedCustomize, customize, customizer)
  }

  return mergedCustomize
}
Example #2
Source File: CommonUtils.ts    From legend-studio with Apache License 2.0 6 votes vote down vote up
mergeObjects = <T, V>(
  obj1: T,
  obj2: V,
  createClone: boolean,
): T & V =>
  mergeWith(
    createClone ? deepClone(obj1) : obj1,
    obj2,
    (o1: object, o2: object): object | undefined => {
      if (Array.isArray(o1)) {
        return o1.concat(o2);
      }
      return undefined;
    },
  )