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

Remove lodash dependency and replace its usage to built-in JavaScript methods #3653

Open
5 tasks
ananzh opened this issue Mar 22, 2023 · 0 comments
Open
5 tasks
Labels
dependencies Pull requests that update a dependency file good first issue Good for newcomers technical debt If not paid, jeapardizes long-term success and maintainability of the repository.

Comments

@ananzh
Copy link
Member

ananzh commented Mar 22, 2023

Lodash is a popular JavaScript library that provides a collection of utility functions for working with arrays, objects, strings, and other data types. It is designed to simplify and enhance the process of writing JavaScript code by offering a rich set of utility functions that are performant and consistent across different environments.

OSD uses lodash, a library for the previous era of JS. For fewer dependencies, lesser memory usage, and faster execution, lodash should be abandoned in favor of native built-in methods. Native built-in JavaScript methods can be a better choice than using a utility library like Lodash. Modern JavaScript engines have improved performance for built-in methods, and browsers have implemented most of the ECMAScript features that make working with arrays, objects, and strings easier.

The first task to start this project is to do a research about where we use lodash

Goal for this task: Identify and list Lodash functions used in the project: Go through our codebase and create a list of all Lodash functions that are being used.

Based on the usage, we should make a proposal to replace lodash methods to native built-in JavaScript methods. For example,

  • _.map → Array.prototype.map
  • _.filter → Array.prototype.filter
  • _.reduce → Array.prototype.reduce
  • _.find → Array.prototype.find
  • _.some → Array.prototype.some
  • _.every → Array.prototype.every
  • _.includes → Array.prototype.includes or String.prototype.includes
  • _.isArray → Array.isArray
  • _.isObject → Use typeof and check for null
  • _.debounce → Implement your own debounce function or use a smaller dedicated library

Then based on the detailed locations and the proposal, continuously divide the implementation into smaller sub-tasks. For example, given a brief search, lodash is used in files like src/cli/cli.js, packages/opensearch-safer-lodash-set/fp/index.d.ts, packages/osd-ace/src/ace/modes/lexer_rules/x_json_highlight_rules.ts and etc. So a nature way to divide the big implementation is to make sub-tasks based on usage locations:

  • [lodash clean] clean and replace lodash usage in opensearch-safer-lodash-set package
  • [lodash clean] clean and replace lodash usage in osd-ace package
  • [lodash clean] clean and replace lodash usage in src/cli directory

Of course, this is just one way to make sub-tasks. Feel free to propose different ways that you would like to divide the implementation work.

@ananzh ananzh added the OSCI Open Source Contributor Initiative label Mar 22, 2023
@ananzh ananzh added good first issue Good for newcomers dependencies Pull requests that update a dependency file and removed untriaged labels Mar 22, 2023
@joshuarrrr joshuarrrr added the technical debt If not paid, jeapardizes long-term success and maintainability of the repository. label Mar 22, 2023
@ashwin-pc ashwin-pc removed the OSCI Open Source Contributor Initiative label Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Pull requests that update a dependency file good first issue Good for newcomers technical debt If not paid, jeapardizes long-term success and maintainability of the repository.
Projects
None yet
Development

No branches or pull requests

3 participants