I need to check for a value of an object field and depending on that I want to set an ReactiveVar variable.
But this field is just an optional one, so maybe it doesn't exists at all. What is the correct way to check the value?
If I would just use var result = (data.profile.anyField == 'something' ) I would get an error as I can't use anyField of undefined, if profile isn't set.
So I would do it like this, but I think it can be done a little bit smarter and shorter:
var modus;
if (Data.profile) modus = (Data.profile.anyField == 'something') ? 'setValue' : '';
else modus = '';
this.modus = new ReactiveVar(modus);
And the second question is if it is correct to set the value of modus to an empty string? The result should be like this:
this.modus = new ReactiveVar('setValue'); // if modus is true
this.modus = new ReactiveVar(); // if modus is false
ReativeVardo? It depends on that if you can or can't pass in an empty string. You could dovar modus = data && data.profile && data.profile.anyField == 'something' ? 'setValue' : '';