Skip to content

Removed dependency on lodash.assign #395

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

Merged
merged 13 commits into from
Feb 25, 2020
Merged

Conversation

zashraf1985
Copy link
Contributor

@zashraf1985 zashraf1985 commented Feb 14, 2020

Summary

to reduce package size, we are trying to gradually get rid of lodash library. This PR replaces assign function with Object.assign. Also added a polyfill method to support old browsers. Polyfill was taken from MDN.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill

Test Plan

All tests pass after this change.

@coveralls
Copy link

coveralls commented Feb 14, 2020

Coverage Status

Coverage decreased (-0.2%) to 97.384% when pulling a7410b4 on zeeshan/replace_lodash_assign into 037f466 on master.

@zashraf1985 zashraf1985 marked this pull request as ready for review February 15, 2020 06:14
@zashraf1985 zashraf1985 requested a review from a team as a code owner February 15, 2020 06:14
@zashraf1985 zashraf1985 changed the title Replaced lodash assign with Object.assign Removed depency on lodah.assign Feb 15, 2020
@zashraf1985 zashraf1985 changed the title Removed depency on lodah.assign Removed depency on lodash.assign Feb 15, 2020
@zashraf1985 zashraf1985 changed the title Removed depency on lodash.assign Removed dependency on lodash.assign Feb 15, 2020
var applyPolyfills = function() {
if (typeof Object.assign !== 'function') {
// Must be writable: true, enumerable: false, configurable: true
Object.defineProperty(Object, "assign", {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not mutate global objects. I suggest to compare these 3 options and choose the one that results in smallest bundle size:

  1. Include this same helper function, but just call it if Object.assign isn't available, instead of mutating the global Object.
  2. Use object-assign library from npm (https://www.npmjs.com/package/object-assign)
  3. Use TypeScript with object spread syntax

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using typescript for only this looked like an overkill to me. I went for option 1 which will have no implact on the bundle size. I also modified all lodash.assignIn usages to use assign instead because it looks like we are not dealing with inherited properties here.

@mjc1283 mjc1283 merged commit a1c18ff into master Feb 25, 2020
@mjc1283 mjc1283 deleted the zeeshan/replace_lodash_assign branch February 25, 2020 23:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants