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

Maintenance: Drop Lodash #26

Closed
fbartho opened this issue May 19, 2022 · 5 comments
Closed

Maintenance: Drop Lodash #26

fbartho opened this issue May 19, 2022 · 5 comments

Comments

@fbartho
Copy link
Collaborator

fbartho commented May 19, 2022

Lodash is a big, regularly updating dep. We only use 2 modules from it, and it #21 we discussed dropping lodash for other techniques.

Describe the solution you'd like
Replace lodash.clone and lodash.isequal with simple JS-built-in options such as structuredClone or JSON.parse(JSON.stringify and Object.isEqual

Describe alternatives you've considered
Leave lodash alone :leave-britney-gif:

@mpcsh
Copy link

mpcsh commented Jun 20, 2022

Hey, I was bored so I took a stab at this. My $0.02 is you should leave lodash alone — here's why:

  • lodash.isEqual is too useful and too annoying to replicate. Object.isEqual isn't a thing, much as I wish :lolsob:
  • lodash.clone seems to preserve type information whereas structuredClone / JSON.parse(JSON.stringify) don't. For example, consider the map predicate in this line:
    • If you try to refactor it to just be structuredClone by reference, you get a type error on structuredClone's second parameter (an options bag), because map predicates are supposed to take the element index as the second parameter.
    • If you then try to refactor it to be (node) => structureClone(node) to get around that type error, the finalNodesClone array gets typed as any, whereas lodash.clone correctly types it as ImportOrLine[]. This doesn't yield any errors (unless you use noImplicitAny), but it does introduce implicit anys, which can cause TypeScript to unexpectedly let you down.

@jasikpark
Copy link

@jasikpark
Copy link

https://github.com/angus-c/just 👀

@ArnaudBarre
Copy link
Contributor

structuredClone is too young anyway to be used in a wide project, but in 1/2 years I think the the default node types would be improved to keep type information. Or it could be wrap in a one liner like: const clone = <T>(value: T): T => structureClone(value). Using a runtime lib just for a bad default types is not ideal IMO.

@IanVS
Copy link
Owner

IanVS commented Jun 21, 2022

I'm inclined to keep what we have for now, since:

  1. Lodash is battle tested, and it's been working fine for us so far as far as I know.
  2. It has good typescript support
  3. It sounds like there are not great native solutions just yet.

Happy to reconsider, but using two small functions from lodash seems fine in my opinion.

@IanVS IanVS closed this as not planned Won't fix, can't repro, duplicate, stale Jul 25, 2022
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

No branches or pull requests

5 participants