Skip to content

Commit

Permalink
refactor: replace lodash/assignWith with vanilla js
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyunhe committed Mar 18, 2024
1 parent 937f845 commit cc0078f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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",
Expand Down Expand Up @@ -101,6 +100,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",
Expand Down
6 changes: 3 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions src/utils/with-default-props.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import assignWith from 'lodash/assignWith'

export function mergeProps<A, B>(a: A, b: B): B & A
export function mergeProps<A, B, C>(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
}

0 comments on commit cc0078f

Please sign in to comment.