Skip to content

Infra/lodash babel plugin #1815

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 8 commits into from
Feb 7, 2022
Merged

Infra/lodash babel plugin #1815

merged 8 commits into from
Feb 7, 2022

Conversation

lidord-wix
Copy link
Contributor

Description

Reduce bundle size using lodash babel plugin - https://github.com/lodash/babel-plugin-lodash
As part of it, I was needed to migrate all the usages of _.chain to _.flow, since _.chain brings all lodash with it.
I recommend reviewing this PR by commit since one of the commits is only for formatting
WOAUILIB-2485

Changelog

Reduce bundle size using lodash babel plugin

@lidord-wix lidord-wix requested a review from M-i-k-e-l February 1, 2022 10:22
@ethanshar ethanshar requested review from ethanshar and removed request for M-i-k-e-l February 2, 2022 07:53
@ethanshar ethanshar assigned ethanshar and unassigned M-i-k-e-l Feb 2, 2022
Copy link
Collaborator

@M-i-k-e-l M-i-k-e-l left a comment

Choose a reason for hiding this comment

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

A general comment, I see a lot of places where you wrote arr (mainly) or str and not used the original name, was that intentional or some autogeneration?

@lidord-wix
Copy link
Contributor Author

A general comment, I see a lot of places where you wrote arr (mainly) or str and not used the original name, was that intentional or some autogeneration?

Actually, I preferred to use arr | str | obj as a parameter to make it clear that it's a pure function that I pass to _.flow(),
but if it's not clear I can change it.
I can also save those functions in a different consts and pass them that way if you find it more readable

@M-i-k-e-l
Copy link
Collaborator

Actually, I preferred to use arr | str | obj as a parameter to make it clear that it's a pure function that I pass to _.flow(), but if it's not clear I can change it.

I think that if you have a proper name (items) you should use that, in other places (keys of props) it might be ok to use arr.
This might be a matter of taste, so maybe we need anther dev's input on this, your choice.

I can also save those functions in a different consts and pass them that way if you find it more readable

Tough one, it might be more readable but it might be less readable with wrong name(s), it will also make the code a bit longer, I think this is generally better (unless you have really good names and \ or repeating functions in the same class).

Copy link
Collaborator

@ethanshar ethanshar left a comment

Choose a reason for hiding this comment

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

Just FYI, there was no reason to change usages outside of the src files (:
We only deliver the src files and we babel only them.

Anyway, Have you checked If the exported files got their lodash imports changed?

Comment on lines 7 to 13
_(b).keys().forEach((key) => {
// @ts-ignore
Object.defineProperty(a, key, Object.getOwnPropertyDescriptor(b, key));
});
_.flow(_.keys, arr =>
_.forEach(arr, key => {
// @ts-ignore
Object.defineProperty(a, key, Object.getOwnPropertyDescriptor(b, key));
}))(b);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you change here if there's no _.chain?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@ethanshar ethanshar Feb 7, 2022

Choose a reason for hiding this comment

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

Wouldn't it be enough to just change it to _.keys(b).forEach? Would that work?
I personally find the _.flow API not very readable, so whenever possible, I'd use a different approach.

In this case we can also use vanilla JS and do Object.keys(b).forEach

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.
I changed to vanilla JS where I found it more readable and also renamed the parameters of the methods as Miki suggested.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Cool! 👌

@lidord-wix
Copy link
Contributor Author

Just FYI, there was no reason to change usages outside of the src files (: We only deliver the src files and we babel only them.

Anyway, Have you checked If the exported files got their lodash imports changed?

Yes, it does change the imports :)

@lidord-wix lidord-wix requested a review from ethanshar February 7, 2022 08:31
@ethanshar ethanshar merged commit 94913a3 into master Feb 7, 2022
M-i-k-e-l added a commit that referenced this pull request Feb 7, 2022
lidord-wix pushed a commit that referenced this pull request Feb 7, 2022
lidord-wix added a commit that referenced this pull request Feb 13, 2022
M-i-k-e-l pushed a commit that referenced this pull request Feb 13, 2022
* Revert "Revert "Infra/lodash babel plugin (#1815)" (#1825)"

This reverts commit b7464cb.

* comment out lodash plugin

* remove commented code
@lidord-wix lidord-wix deleted the infra/lodash_babel_plugin branch February 22, 2022 13:05
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.

3 participants