Skip to content

Commit

Permalink
refactor: replace lodash/assignWith with vanilla js (ant-design#6581)
Browse files Browse the repository at this point in the history
* refactor: replace lodash/assignWith with vanilla js

* fix: size limit
  • Loading branch information
guoyunhe authored Mar 28, 2024
1 parent 7d75de6 commit bfbc96e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
6 changes: 4 additions & 2 deletions .github/workflows/size-limit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ on:
types: [opened, synchronize]

permissions:
contents: read
contents: write
pull-requests: write

jobs:
size:
permissions:
contents: read
checks: read
contents: write
pull-requests: write
runs-on: ubuntu-latest

Expand Down
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 bfbc96e

Please sign in to comment.