Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: replace lodash/assignWith with vanilla js #6581

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading