Add documentation for AppUsage

Also make ternary operators easier to read.
This commit is contained in:
chrisgarrity 2017-08-23 11:53:13 -04:00
parent 7a530be88b
commit 0f2c31bfc9

View file

@ -7,22 +7,35 @@ export default class AppUsage {
return currentUsage;
}
/**
* Initialize currentUsage for attaching to Analytics events from
* the usage cookie if it is set. currentUsage is blank if the cookie is
* not set.
*/
static initUsage () {
const usageCookie = Cookie.get('usage');
currentUsage = usageCookie ? usageCookie + '::' : '';
currentUsage = (usageCookie) ? usageCookie + '::' : '';
}
/**
* Check whether the App should ask for the usage data (first time launched)
* @return {boolean} True if the usage cookie has never been set
*/
static askForUsage () {
var usageCookie = Cookie.get('usage');
return usageCookie === null;
}
/**
* Set the usage cookie for tracking Analytics Events
* @param {string} kind answer from user to the usage survey (home, school, other, noanswer)
*/
static setUsage (kind) {
if (kind === '') {
Cookie.set('usage', 'noanswer');
} else {
Cookie.set('usage', kind);
}
currentUsage = kind === 'noanswer' ? '' : '_' + kind;
currentUsage = (kind === '') ? 'noanswer::' : kind + '::';
}
}