-
Notifications
You must be signed in to change notification settings - Fork 479
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
using optional chaining (?.) in the getUserVariant function #1445
Open
ATella12
wants to merge
4
commits into
base-org:master
Choose a base branch
from
ATella12:patch-2
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…fy the logic and reduce the need for explicit null checks Problems/opportunities for improvement: The check for experimentClient being null or undefined is redundant, and the code can be cleaner using optional chaining. You also don't need the explicit if statement for experimentClient because the optional chaining operator will automatically handle it. Using Optional Chaining: Optional chaining allows you to access deeply nested properties without explicitly checking for null or undefined. If any part of the chain is null or undefined, the expression evaluates to undefined instead of throwing an error. What’s Changed: 1. Optional Chaining (?.): The line const variant = experimentClient?.variant(flagKey); uses optional chaining. This ensures that: If experimentClient is null or undefined, the code will safely return undefined instead of trying to call .variant(flagKey) and throwing an error. If experimentClient is valid, it proceeds to call variant(flagKey). 2. Simplified Logic: Since optional chaining handles the null/undefined check for you, you no longer need the explicit check for experimentClient. This reduces code clutter and makes it easier to maintain. 3. Error Handling: After getting the variant, we check if the variant exists. If it’s undefined (e.g., if the flag key doesn’t correspond to any variant), we log an error and return undefined. Thanks for reviewing this.
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
🟡 Heimdall Review Status
|
@ATella12 is attempting to deploy a commit to the Coinbase Team on Vercel. A member of the Team first needs to authorize it. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problems improved:
The check for experimentClient being null or undefined is redundant, and the code can be cleaner using optional chaining.
You also don't need the explicit if statement for experimentClient because the optional chaining operator will automatically handle it.
Using Optional Chaining:
Optional chaining allows you to access deeply nested properties without explicitly checking for null or undefined. If any part of the chain is null or undefined, the expression evaluates to undefined instead of throwing an error.
What’s Changed:
Optional Chaining (?.):
The line const variant = experimentClient?.variant(flagKey); uses optional chaining. This ensures that If experimentClient is null or undefined, the code will safely return undefined instead of trying to call .variant(flagKey) and throwing an error. If experimentClient is valid, it proceeds to call variant(flagKey).
Simplified Logic: Since optional chaining handles the null/undefined check for you, you no longer need the explicit check for experimentClient. This reduces code clutter and makes it easier to maintain.
Error Handling: After getting the variant, we check if the variant exists. If it’s undefined (e.g., if the flag key doesn’t correspond to any variant), we log an error and return undefined.
Thanks for reviewing this.