-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Block Editor: use optional chaining and nullish coalescing instead of Lodash.get. #23632
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 optional chaining and nullish coalescing instead of Lodash.get. #23632
Conversation
|
Size Change: +87 B (0%) Total Size: 1.17 MB
ℹ️ View Unchanged
|
a3d1cf9 to
7a19d11
Compare
7a19d11 to
7f257fa
Compare
7f257fa to
6e4688d
Compare
youknowriad
left a comment
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.
I find these refactorings a bit useless tbh but 🤷♂️
| [ 'onChange' ], | ||
| null | ||
| ), | ||
| preferredStyle: preferredStyleVariations?.value?.[ blockName ], |
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.
In this instance, I find the previous implementation a lot more clear.
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.
I dunno, it seems clearer to me. 🤔
Description
See title. Optional chaining and nullish coalescing are (recent) standard JS features that we already use across our codebase, so this PR helps increase consistency by updating cases where we were using Lodash.get. The native JS syntax is also a lot easier to comprehend, in my opinion.
Since there are a lot of places where
_.getis being used right now, I'm doing this one package at a time, to make it easier to review.It's worth noting there are a few cases where using
_.getactually does make sense: cases where the object path has a dynamic level of nesting, which as far as I am aware, cannot be expressed using optional chaining. Those cases have been left unchanged.This is part of a series of code quality PRs I am working on. The long-term goal is to reduce
lodashusage in cases where a standard JS function/syntax 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 (Lodash often silently ignores nullish values) and avoiding the use of external libraries when simple equivalents exist in standard JS.