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

Avoid lodash where possible #1500

Merged
merged 8 commits into from
Oct 3, 2020
Merged

Avoid lodash where possible #1500

merged 8 commits into from
Oct 3, 2020

Conversation

TrySound
Copy link
Contributor

@TrySound TrySound commented Oct 1, 2020

Lodash is quite big package https://packagephobia.com/result?p=lodash
and often used where modern javascript feature do a good job.

In this diff I replaced lodash with native functions or for/of loop.

The only left case is lodash/cloneDeepWith which does not have clear
alternative. I will try to replace it with something in another PR and
remove lodash dependency.

Lodash is quite big package https://packagephobia.com/result?p=lodash
and often used where modern javascript feature do a good job.

In this diff I replaced lodash with native functions or for/of loop.

The only left case is lodash/cloneDeepWith which does not have clear
alternative. I will try to replace it with something in another PR and
remove lodash dependency.
@TrySound
Copy link
Contributor Author

TrySound commented Oct 1, 2020

cc @fb55

Copy link
Member

@fb55 fb55 left a comment

Choose a reason for hiding this comment

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

Great PR, thanks for looking into this! Left some comments, there are some patterns that can be simplified. Also, it would be great if we could avoid using iterators (both with for .. of loops and with Array.from, as some users are still using older JS engines. Note that this isn't forever & we will upgrade eventually.

lib/api/css.js Outdated Show resolved Hide resolved
lib/api/attributes.js Outdated Show resolved Hide resolved
lib/api/traversing.js Outdated Show resolved Hide resolved
@TrySound
Copy link
Contributor Author

TrySound commented Oct 2, 2020

I relied on travis.yaml and thought only node lts are supported. Also what about arrow functions? They are used a lot instead of "bind".

@TrySound
Copy link
Contributor Author

TrySound commented Oct 2, 2020

@fb55 I converted all changes to es5

@TrySound
Copy link
Contributor Author

TrySound commented Oct 2, 2020

Though I left Object.assign as there is no alternative in es5

Copy link
Member

@fb55 fb55 left a comment

Choose a reason for hiding this comment

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

A lot of great stuff here! There are still a few too many forEach here for my taste, that should either be replaced with reduce calls, or good old for loops. Otherwise this should be good to go soon.

Also agreed that Object.assign seems alright to keep around. Users can easily polyfill it if it isn't available.

.eslintrc.json Outdated
@@ -6,14 +6,6 @@
"extends": ["eslint:recommended", "prettier"],
"globals": {},
"rules": {
"indent": [
Copy link
Member

Choose a reason for hiding this comment

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

Can we leave this rule enabled? This PR has quite a few whitespace changes & I'd prefer to keep those separate.

Copy link
Contributor Author

@TrySound TrySound Oct 3, 2020

Choose a reason for hiding this comment

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

You have prettier enabled. And its formatting is different from eslint one. I needed passed eslint to test properly.
https://github.com/cheeriojs/cheerio/blob/v1.0.0/package.json#L59-L62

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see. Pre-commit package is missing.

lib/api/manipulation.js Outdated Show resolved Hide resolved
lib/api/manipulation.js Outdated Show resolved Hide resolved
lib/api/traversing.js Outdated Show resolved Hide resolved
test/cheerio.js Outdated Show resolved Hide resolved
@fb55
Copy link
Member

fb55 commented Oct 2, 2020

The only left case is lodash/cloneDeepWith which does not have clear alternative. I will try to replace it with something in another PR and remove lodash dependency.

I've just added a cloneNode method to domhandler, which should remove the need for this method altogether.

@TrySound
Copy link
Contributor Author

TrySound commented Oct 3, 2020

@fb55 Done

@fb55 fb55 merged commit 2337c1a into cheeriojs:v1.0.0 Oct 3, 2020
@fb55
Copy link
Member

fb55 commented Oct 3, 2020

Awesome work, thank you so much!

@TrySound TrySound deleted the avoid-lodash branch October 3, 2020 17:56
@TrySound
Copy link
Contributor Author

TrySound commented Oct 4, 2020

Hi @fb55. I don't see cloneNode available in cheerio nodes. Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants