From 7c36a96af788ffc2f8ab4b9208cf7ab4ed847bdc Mon Sep 17 00:00:00 2001 From: Guo Yunhe Date: Tue, 6 Feb 2024 22:09:48 +0800 Subject: [PATCH] refactor: replace lodash/assignWith with vanilla js --- package.json | 2 +- pnpm-lock.yaml | 10 ---------- src/utils/with-default-props.tsx | 18 ++++++++---------- 3 files changed, 9 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index b888de0996..e0a3887bdf 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,6 @@ "classnames": "^2.3.2", "dayjs": "^1.11.7", "deepmerge": "^4.3.1", - "lodash": "^4.17.21", "nano-memoize": "^3.0.16", "rc-field-form": "~1.27.4", "rc-util": "^5.38.1", @@ -98,6 +97,7 @@ "jest-environment-jsdom": "^28.1.3", "jest-watch-typeahead": "^1.1.0", "less": "^4.1.3", + "lodash": "^4.17.21", "lorem-ipsum": "^2.0.8", "lz-string": "^1.5.0", "mockdate": "^3.0.5", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index f7bd23fe20..c1847b314a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -39,9 +39,6 @@ dependencies: deepmerge: specifier: ^4.3.1 version: 4.3.1 - lodash: - specifier: ^4.17.21 - version: 4.17.21 nano-memoize: specifier: ^3.0.16 version: 3.0.16 @@ -131,9 +128,6 @@ devDependencies: '@types/jest-axe': specifier: 3.5.4 version: 3.5.4 - '@types/lodash': - specifier: ^4.14.194 - version: 4.14.198 '@types/node': specifier: ^18.15.13 version: 18.17.17 @@ -3687,10 +3681,6 @@ packages: '@types/node': 20.4.7 dev: true - /@types/lodash@4.14.198: - resolution: {integrity: sha512-trNJ/vtMZYMLhfN45uLq4ShQSw0/S7xCTLLVM+WM1rmFpba/VS42jVUgaO3w/NOLiWR/09lnYk0yMaA/atdIsg==} - dev: true - /@types/mathjax@0.0.36: resolution: {integrity: sha512-TqDJc2GWuTqd/m+G/FbNkN+/TF2OCCHvcawmhIrUaZkdVquMdNZmNiNUkupNg9qctorXXkVLVSogZv1DhmgLmg==} dev: true diff --git a/src/utils/with-default-props.tsx b/src/utils/with-default-props.tsx index 1780272000..3446d7dea6 100644 --- a/src/utils/with-default-props.tsx +++ b/src/utils/with-default-props.tsx @@ -1,15 +1,13 @@ -import assignWith from 'lodash/assignWith' - export function mergeProps(a: A, b: B): B & A export function mergeProps(a: A, b: B, c: C): C & B & A export function mergeProps(...items: any[]) { - function customizer(objValue: any, srcValue: any) { - return srcValue === undefined ? objValue : srcValue - } - - let ret = { ...items[0] } - for (let i = 1; i < items.length; i++) { - ret = assignWith(ret, items[i], customizer) - } + const ret: any = {} + items.forEach(item => { + Object.keys(item).forEach(key => { + if (item[key] !== undefined) { + ret[key] = item[key] + } + }) + }) return ret }