-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Lodash: Refactor away from _.sortBy()
#43479
Conversation
Size Change: +165 B (0%) Total Size: 1.24 MB
ℹ️ View Unchanged
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you @tyxla! 👍
Left a comment suggesting a simpler alternative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 from me on the Nav block and changelog changes. TIL about localeCompare
as well 👏
What?
This PR removes the
_.sortBy()
usage completely and deprecates the function.Why?
Lodash is known to unnecessarily inflate the bundle size of packages, and in most cases, it can be replaced with native language functionality. See these for more information and rationale:
@wordpress/api-fetch
package haslodash
as a dependency #39495How?
We're using the native
Array.prototype.sort()
function with some custom comparison functions which are pretty straightforward to write.In Lodash, this is one one of the useful functions, as it saves a little boilerplate necessary for the sorting, which is especially handy for multiple criteria. Here, we only have a single use for that, and refactoring it is pretty straightforward.
However, the function is also pretty complex, as it supports objects (which we don't need here and is confusing since it grabs an object and returns an array), and flattens the input collection, which we also don't need.
We can totally abstract this to a helper function, but given the usages here I just think it's not necessary.
Testing Instructions
npm run other:changelog
and verify changelog is still built correctly. Specifically, verify the list of contributors is still sorted by the username alphabetically.@wordpress/babel-plugin-makepot
- cc @swisspidy - what's a good way to test this one nowadays?