added first A/B experiment
This commit is contained in:
parent
14e21988b2
commit
17e61bb09d
9 changed files with 159 additions and 10 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue