Currently my DF's cumpute() starts with:
var hr = (info != null && info has :currentHeartRate && info.currentHeartRate != null)
? info.currentHeartRate
: "--";
Should I check info has :currentHeartRate in every call to compute() or can I cache it:
if (mHasCurrentHR == null && info != null) {
mHasCurrentHR = info has :currentHeartRate;
}
var hr = mHasCurrentHR == true && info != null && info.currentHeartRate != null ? info.currentHeartRate : "--";
Or in other words: does info always have :currentHeartRate on a specific device, even when there won't be HR for a while or can it "surprise me" that sometimes it'll have a non-null info that doesn't even has a null info.currentHeartRate?
Or do I even need to bother with the has? Can I just write:
var hr = (info != null && info.currentHeartRate != null)
? info.currentHeartRate
: "--";
Or even better: can I move this to initialize somehow?
function initialize() {
var info = ActivityMonitor.getInfo();
mHasCurrentHR = info has :currentHeartRate;
}
Can I be sure that the info I get this way indicates regarding has :currentHeartRate what will the info sent to compute(info) be like?