From f83fd61ff8fa1035fd97df7c8b6c8bd528880755 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mir=C3=B3=20Sorja?= Date: Mon, 14 Oct 2024 09:40:51 +0300 Subject: [PATCH] 4000 - use lodash.merge --- package.json | 2 ++ src/utils/objects/index.ts | 5 +++-- src/utils/objects/mergePartial.ts | 33 ------------------------------- yarn.lock | 7 +++++++ 4 files changed, 12 insertions(+), 35 deletions(-) delete mode 100644 src/utils/objects/mergePartial.ts diff --git a/package.json b/package.json index 3f2346ee66..32364b4c1c 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "@types/lodash.isequal": "^4.5.5", "@types/lodash.isfunction": "^3.0.6", "@types/lodash.isnil": "^4.0.6", + "@types/lodash.merge": "^4.6.9", "@types/lodash.pick": "^4.4.7", "@types/lodash.range": "^3.2.6", "@types/lodash.reverse": "^4.0.6", @@ -213,6 +214,7 @@ "lodash.isequal": "^4.5.0", "lodash.isfunction": "^3.0.9", "lodash.isnil": "^4.0.0", + "lodash.merge": "^4.6.2", "lodash.pick": "^4.4.0", "lodash.range": "^3.2.0", "lodash.reverse": "^4.0.1", diff --git a/src/utils/objects/index.ts b/src/utils/objects/index.ts index ebae77d1c6..6d9979988c 100644 --- a/src/utils/objects/index.ts +++ b/src/utils/objects/index.ts @@ -7,6 +7,8 @@ import * as isFunction from 'lodash.isfunction' // @ts-ignore import * as isNil from 'lodash.isnil' // @ts-ignore +import * as merge from 'lodash.merge' +// @ts-ignore import * as pick from 'lodash.pick' // @ts-ignore import * as unset from 'lodash.unset' @@ -15,7 +17,6 @@ import { getInPath } from 'utils/objects/getInPath' import { camelize } from './camelize' import { getDiffAsPartialObject } from './getDiffAsPartialObject' import { isEmpty } from './isEmpty' -import { mergePartial } from './mergePartial' import { propertyOf } from './propertyOf' import { setInPath } from './setInPath' @@ -28,7 +29,7 @@ export const Objects = { isEqual, isFunction, isNil, - mergePartial, + merge, pick, propertyOf, setInPath, diff --git a/src/utils/objects/mergePartial.ts b/src/utils/objects/mergePartial.ts deleted file mode 100644 index 52e3c6f6b1..0000000000 --- a/src/utils/objects/mergePartial.ts +++ /dev/null @@ -1,33 +0,0 @@ -/** - * Merges a partial object or array into a base object or array, recursively handling nested structures. - * - * @template T - The type of the base object or array - * @param {T} base - The original object or array to be updated - * @param {Partial} partial - The partial object or array containing updates - * @returns {T} The updated base object or array after merging - * - * @example - * const baseObj = { a: 1, b: { c: 2 } }; - * const partialObj = { b: { d: 3 } }; - * const resultObj = mergePartial(baseObj, partialObj); - * // resultObj: { a: 1, b: { c: 2, d: 3 } } - * - * @example - * const baseArr = [1, 2, { a: 3 }]; - * const partialArr = [4, undefined, { b: 5 }]; - * const resultArr = mergePartial(baseArr, partialArr); - * // resultArr: [4, 2, { a: 3, b: 5 }] - */ -export const mergePartial = (obj1: any, partial: any): any => { - Object.keys(partial).forEach((key) => { - const isObject = typeof partial[key] === 'object' && partial[key] !== null - if (isObject) { - // eslint-disable-next-line no-param-reassign - obj1[key] = mergePartial(obj1[key], partial[key]) - } else { - // eslint-disable-next-line no-param-reassign - obj1[key] = partial[key] - } - }) - return obj1 -} diff --git a/yarn.lock b/yarn.lock index 4791fc9908..feba34d21d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2514,6 +2514,13 @@ dependencies: "@types/lodash" "*" +"@types/lodash.merge@^4.6.9": + version "4.6.9" + resolved "https://registry.yarnpkg.com/@types/lodash.merge/-/lodash.merge-4.6.9.tgz#93e94796997ed9a3ebe9ccf071ccaec4c6bc8fb8" + integrity sha512-23sHDPmzd59kUgWyKGiOMO2Qb9YtqRO/x4IhkgNUiPQ1+5MUVqi6bCZeq9nBJ17msjIMbEIO5u+XW4Kz6aGUhQ== + dependencies: + "@types/lodash" "*" + "@types/lodash.pick@^4.4.7": version "4.4.9" resolved "https://registry.yarnpkg.com/@types/lodash.pick/-/lodash.pick-4.4.9.tgz#06f7d88faa81a6c5665584778aea7b1374a1dc5b"