[
https://issues.apache.org/jira/browse/HDDS-11229?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Arafat Khan updated HDDS-11229:
-------------------------------
Fix Version/s: 1.5.0
Resolution: Fixed
Status: Resolved (was: Patch Available)
> Recon Code Optimization for use of Optional Chaining Insight Module.
> --------------------------------------------------------------------
>
> Key: HDDS-11229
> URL: https://issues.apache.org/jira/browse/HDDS-11229
> Project: Apache Ozone
> Issue Type: Improvement
> Reporter: smita
> Assignee: smita
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.5.0
>
>
> Currently we are using explicit undefined checks for statements.
> [Sample|https://github.com/apache/ozone/blob/dcfa3b42ba830781de589d13b30162a426ad3a3d/hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/views/missingContainers/missingContainers.tsx#L401]:
> {code:javascript}
> `Missing${(missingDataSource && missingDataSource.length > 0) ? `
> (${missingDataSource.length})` : ''}
> {code}
> This causes lots of unnecessary code to be written as guard clauses.
> JavaScript offers optional chaining feature which would allow us to skip such
> checks and make our code more readable.
> Optional chaining will short-circuit the check and return undefined if at any
> step the accessed property is undefined so we do not need to handle so many
> checks.
> The above sample code can be written as:
> {code:javascript}
> `Missing${(missingDataSource?.length > 0) ? ` (${missingDataSource.length})`
> : ''}
> {code}
> where if missingDataSource is undefined, then the expression evaluates to:
> {code:javascript}
> (undefined > 0)
> {code}
> which will return false and hence achieve the same result in a more compact
> syntax
--
This message was sent by Atlassian Jira
(v8.20.10#820010)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]