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

Solar quantity table summary #1287

Merged
merged 2 commits into from
Jul 1, 2024
Merged

Conversation

blammit
Copy link
Contributor

@blammit blammit commented Jun 30, 2024

No description provided.

We must handle the case where dailyHistory() returns a null object,
otherwise acccessing yieldKwh on the null object results in an
undefined access error.

This fixes it to use NaN if dailyHistory() returns null.

Fixes #1280
@@ -30,7 +30,7 @@ Page {
},
{
title: CommonWords.yield_today,
value: root.solarCharger.dailyHistory(0).yieldKwh || 0,
value: solarCharger.dailyHistory(0)?.yieldKwh ?? NaN,
Copy link
Contributor Author

@blammit blammit Jun 30, 2024

Choose a reason for hiding this comment

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

Note, this is equivalent to:

const history = solarCharger.dailyHistory(0)
return history ? history.yieldKwh : NaN

The syntax takes some getting used to, but it'd be nice to get rid of the "if null return NaN" repetitive pattern throughout the codebase.

See https://en.wikipedia.org/wiki/Null_coalescing_operator and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining.

@blammit blammit merged commit d5da616 into main Jul 1, 2024
1 check passed
@blammit blammit deleted the blam/solar-quantity-table-summary branch July 1, 2024 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants