-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Block editor: use vanilla JS Array.prototype.includes instead of Lodash #21063
Block editor: use vanilla JS Array.prototype.includes instead of Lodash #21063
Conversation
Size Change: -24 B (0%) Total Size: 1.13 MB
ℹ️ View Unchanged
|
The test failures are because I'm using optional chaining. This PR is blocked by #19952. |
@ZebulanStanphill Any reason it wouldn't work to land all the instances except the one which uses optional chaining? Looks like there's only one. |
@chrisvanpatten That's a good point! I've removed that instance from this PR so this can get merged sooner. |
I had to undo another instance because apparently But anyway, all tests are passing now for this PR! |
Forgot to remove the "Blocked" label until now. This PR is ready for review. |
e55d40d
to
b6e547e
Compare
Resolved merge conflicts. |
7f3b7c7
to
76585d1
Compare
342d758
to
089a96a
Compare
docs/designers-developers/developers/data/data-core-block-editor.md
Outdated
Show resolved
Hide resolved
Our tooling now supports optional chaining, so I brought back the changes that were using that. |
Thanks for working on it. I like the idea in general but I have some reservations:
Any ideas how yo encourage first the usage of native JS? |
@gziolo Regarding the discouraging of Lodash use, here are two ideas:
And yeah, I am somewhat relying on the idea that TypeScript integration will continue to improve as it has been lately. (See #18838.) |
089a96a
to
fe97247
Compare
fe97247
to
11c3227
Compare
e19f64a
to
91658de
Compare
91658de
to
7828bfb
Compare
f471ba2
to
86c0095
Compare
86c0095
to
2d78368
Compare
2d78368
to
d97ec7d
Compare
d97ec7d
to
4e69fd8
Compare
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.
The implementation looks right, I share the same concern as @gziolo that it is not truly compatible with lodash, because if a null is passed to lodash includes() it will return false without error, but trying to use the native Array.includes() function will error if called from a null value.
It looks like the variables that might be null use the new ?.
syntax that should handle it, and the majority of updates look like the variable should be defined.
Testing on the branch didn't reveal anything, but hard to test the uses cases here.
With all that, I give it a 👍
Description
See title. In my testing, the vanilla method is slightly faster, and I find it easier to comprehend when reading the code. It also has stronger typing, making it better for pushing the codebase closer to complete type checking.
As it turns out,
lodash.includes
is used a lot in the code, so to make reviewing and catching mistakes easier, I'm doing one package at a time.The long-term goal is to reduce
lodash
usage in cases where a standard JS function works just as well or better, which should reduce our packages' bundle sizes for 3rd parties using them. This will also increase clarity by making nullish value handling more explicit, and avoiding the use of external libraries when simple equivalents exist in standard JS.