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: use object spread instead of Object.assign for new objects #12213

Merged
merged 1 commit into from May 3, 2020

Conversation

SimonSchick
Copy link
Contributor

@SimonSchick SimonSchick commented May 2, 2020

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test or npm run test-DIALECT pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?
  • Did you update the typescript typings accordingly (if applicable)?
  • Did you follow the commit message conventions explained in CONTRIBUTING.md?

Description of change

This replaces most Object.assign usage with the more performant (about 40%) (1) object spread.

  • All cases of Object.assign({}, ...) have been auto refactored by eslint.
  • The remaining ones where objects where composed over multiple lines were manually adjusted.
  • The || {} pattern is not needed as { ...undefined } yields {}.
  • val = Object.assign(val, ...) has been replaced with Object.assign(val, ...) to avoid confusion and redundant assigns.

Notes:

  • (1) Performance may vary by node version, in v10+ spread is generally faster.

@codecov
Copy link

@codecov codecov bot commented May 2, 2020

Codecov Report

Merging #12213 into master will decrease coverage by 0.00%.
The diff coverage is 98.95%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #12213      +/-   ##
==========================================
- Coverage   96.34%   96.33%   -0.01%     
==========================================
  Files          95       95              
  Lines        9183     9169      -14     
==========================================
- Hits         8847     8833      -14     
  Misses        336      336              
Impacted Files Coverage Δ
lib/dialects/mariadb/connection-manager.js 100.00% <ø> (ø)
lib/model.js 96.59% <96.29%> (-0.02%) ⬇️
lib/associations/belongs-to-many.js 98.05% <100.00%> (-0.03%) ⬇️
lib/associations/belongs-to.js 100.00% <100.00%> (ø)
lib/associations/has-many.js 97.63% <100.00%> (-0.03%) ⬇️
lib/associations/has-one.js 97.19% <100.00%> (ø)
lib/associations/mixin.js 100.00% <100.00%> (ø)
lib/dialects/abstract/query-generator.js 97.14% <100.00%> (ø)
lib/dialects/abstract/query-generator/operators.js 90.90% <100.00%> (ø)
lib/dialects/abstract/query.js 91.98% <100.00%> (ø)
... and 15 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5a4d260...03121b1. Read the comment docs.

Copy link
Member

@eseliger eseliger left a comment

This codebase becomes more and more modern :)

.eslintrc.json Show resolved Hide resolved
options = Object.assign({}, options, {
scope: false
});
options = { ...options, scope: false };
Copy link
Member

@eseliger eseliger May 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ideally parameters should be read-only, but that's another problem

Copy link
Contributor Author

@SimonSchick SimonSchick May 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct, I've seen numerous fixes creeping in over time that end up cloning/deep cloning inputs, but this almost impossible to fix on a greater scale without static analysis.

Copy link
Member

@eseliger eseliger May 2, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree

@sushantdhiman sushantdhiman merged commit 6640ba2 into master May 3, 2020
3 of 4 checks passed
@sushantdhiman sushantdhiman deleted the chore/reduce-object-assign branch May 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants