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

chore(v2): replace few Lodash methods with native counterparts #2520

Closed
wants to merge 3 commits into from

Conversation

Simek
Copy link
Contributor

@Simek Simek commented Apr 3, 2020

Motivation

Same motivation like in previous PRs.

This is the initial step in getting rid of main lodash package in core v2 Docusaurus package. In this PR _.compact and _.flatten methods has been replaced with their native counterparts.

Have you read the Contributing Guidelines on pull requests?

Yes

Test Plan

Same test results before and after code refactor.

Related PRs

@Simek Simek requested a review from yangshun as a code owner April 3, 2020 15:40
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Apr 3, 2020
@docusaurus-bot
Copy link
Contributor

docusaurus-bot commented Apr 3, 2020

Deploy preview for docusaurus-2 ready!

Built with commit 2d9fb89

https://deploy-preview-2520--docusaurus-2.netlify.com

@yangshun
Copy link
Contributor

yangshun commented Apr 3, 2020

I think I'd stick with the Lodash versions given they are more readable. Sorry about that.

@yangshun yangshun closed this Apr 3, 2020
@Simek
Copy link
Contributor Author

Simek commented Apr 3, 2020

@yangshun I think that it's not a good approach. This means that v2 core will have two more packages (lodash.compact and lodash.flatten) and two more dev packages (@types/lodash.compact and @types/lodash.flatten) just because of personal preferences.

I don't like either syntax and TS typing issues here personally, but in this case is a matter of preventing the bigger mess.

@yangshun
Copy link
Contributor

yangshun commented Apr 3, 2020

@lex111 what do you think? Do you agree?

@Simek
Copy link
Contributor Author

Simek commented Apr 3, 2020

Also compact + flatten replacement could be extracted to the separate util/helper method if you think this improve readability, but I have no idea where this kind of code should be placed (in which package, which path).

@lex111
Copy link
Contributor

lex111 commented Apr 3, 2020

I actually like what was done in this PR, and it seems to me that these changes do not complicate understanding of the code.

@Simek
Copy link
Contributor Author

Simek commented Apr 3, 2020

@lex111 Should I recreate this PR? I have also added one more minor commit to the changeset since this PR was closed which updates the pluginThemes to match other refactored cases (order of operations).

@lex111
Copy link
Contributor

lex111 commented Apr 3, 2020 via email

@Simek
Copy link
Contributor Author

Simek commented Apr 3, 2020

I have updated the reworked PR and removed also assign and isArray methods. All commits has been squashed. Current version can be seen here: Simek@2084e99

After applying those changes only has, isPlainObject and isString packages are needed in the core. I have a finishing commit stashed, which removes lodash dependency and adds listed above single method packages and typing for them.

Let me know if I should commit those changes in the separate PR after this part will be resolved or add them in reworked version of this PR.

@yangshun
Copy link
Contributor

yangshun commented Apr 4, 2020

Ok let's do this. Could you open a new PR? I can't seem to reopen the PR now because it has been force pushed

@slorber
Copy link
Collaborator

slorber commented Jul 15, 2020

Hey, was wondering what is the motivation to use lodash es exactly?

Personnally I find it highly annoying to have to update package.json everywhere I need a new lodash method.

What's the problem with a regular lodash available in node?

I understand we want to optimize client code, but don't really see the value for node code.

Btw, nothing will enforce the rule of "only lodash ES imports" over time. In fact, some code of mine was already merged and does not use lodash es but regular lodash, so wonder what to do about this?

If there are striong reasons to use lodash ES then we should enforce it with an ESLint import rule, but honnestly I'm not convinced by the value of enforcing such rule (at least for node code)

@slorber
Copy link
Collaborator

slorber commented Jul 15, 2020

What I'd suggest is:

  • prevent lodash import in client code by a nested .eslintrc in client code folders, with import rules preventing import from lodash(ideally, using vanilla js instead of lodash)
  • allow using lodash in any server code, not necessarily from ES imports like this refactor introduced

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

Successfully merging this pull request may close these issues.

6 participants