added first A/B experiment

This commit is contained in:
Danny Coates 2017-09-11 17:09:29 -07:00
parent 14e21988b2
commit 17e61bb09d
No known key found for this signature in database
GPG key ID: 4C442633C62E00CB
9 changed files with 159 additions and 10 deletions

View file

@ -42,7 +42,11 @@ class Storage {
const k = this.engine.key(i);
if (isFile(k)) {
try {
fs.push(JSON.parse(this.engine.getItem(k)));
const f = JSON.parse(this.engine.getItem(k));
if (!f.id) {
f.id = f.fileId;
}
fs.push(f);
} catch (err) {
// obviously you're not a golfer
this.engine.removeItem(k);
@ -70,6 +74,18 @@ class Storage {
set referrer(str) {
this.engine.setItem('referrer', str);
}
get enrolled() {
return JSON.parse(this.engine.getItem('experiments') || '[]');
}
enroll(id, variant) {
const enrolled = this.enrolled;
// eslint-disable-next-line no-unused-vars
if (!enrolled.find(([i, v]) => i === id)) {
enrolled.push([id, variant]);
this.engine.setItem('experiments', JSON.stringify(enrolled));
}
}
get files() {
return this._files;
@ -83,6 +99,10 @@ class Storage {
}
}
get(id) {
return this.engine.getItem(id);
}
remove(property) {
if (isFile(property)) {
this._files.splice(this._files.findIndex(f => f.id === property), 1);