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

Block Editor: Use optional chaining in 'block-list' component #42068

Merged
merged 1 commit into from
Jul 1, 2022
Merged

Block Editor: Use optional chaining in 'block-list' component #42068

merged 1 commit into from
Jul 1, 2022

Conversation

hz-tyfoon
Copy link
Contributor

What?

Hey Everyone. 🙂
Looks like in line number 59 & 62 there's 4 && check can be replaced with 2 optional chaining (?.).

Why?

(?.) already used in line number 190 of this file (packages/block-editor/src/components/block-list/block.js) and many other files in this repository. So, I think (?.) can be used where applicable.

@hz-tyfoon hz-tyfoon requested a review from ellatrix as a code owner June 30, 2022 10:47
Copy link
Contributor

@alexstine alexstine left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hz-tyfoon LGTM.

@Mamaduka Mamaduka changed the title (block-editor: 'block-list' component) code quality - using optional chaining instead of 'more && check' Block Editor: Use optional chaining in 'block-list' component Jul 1, 2022
@Mamaduka
Copy link
Member

Mamaduka commented Jul 1, 2022

Thanks for contributing, @hz-tyfoon.

Both code variants are valid so I would call this a "code modernization." If you check the codebase, you'll find a lot of similar examples. But I don't think it's worth our time and effort to refactor the code that's working.

I would recommend reading WordPress' Code Refactoring handbook for more details - https://make.wordpress.org/core/handbook/contribute/code-refactoring/.

@Mamaduka Mamaduka merged commit 3563947 into WordPress:trunk Jul 1, 2022
@github-actions github-actions bot added this to the Gutenberg 13.7 milestone Jul 1, 2022
@bph bph added [Type] Code Quality Issues or PRs that relate to code quality [Package] Block editor /packages/block-editor labels Jul 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Block editor /packages/block-editor [Type] Code Quality Issues or PRs that relate to code quality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants