Skip to content

Instantly share code, notes, and snippets.

@gregglind
Created March 7, 2012 21:25
Show Gist options
  • Save gregglind/1996340 to your computer and use it in GitHub Desktop.
Save gregglind/1996340 to your computer and use it in GitHub Desktop.
tp2 sample experiment 2
// do we want to do using 'register' instead?
var experiment = new require("test-pilot").Experiment();
// we can even get around the 'new' dangers using the jetpack utils.
// the idea is, it's a 'subclass', so that TP namespace is rolled in to an exp.
experiment.metadata = {
id: "",
summary: "",
}; // is this a problem that it doesn't go through 'guards'?
// sensible defaults, including, id vs. name, database name
// and sensible default fields in the db
// this should be a property? What is a sane default?
experiment.arm = function() {
if (this.locale !== "EN-US") {
return 2;
}
return 1;
}
experiment.startup( function() {
if (this.arm("some_previous_study") == 2) {
this.arm = 2; // i.e., we can reuse arms for longitudinal studies?
}
if (this.arm() == 1) {
this.requre_extension("/some/path.xpi"); // does this register on 'this._extensions'?
this.watch('someSelector',"some_actions_or_*",{'attribute'});
this.Handler(function(){/*some much deeper watch*/}
}
if (this.arm() == 2) {
var ext = this.require_extension("/some/other/thing.xpi");
this.watch(ext.watchlist); // we can put the tests into the extension!?
}
if (this.arm() == 3) {
this.notice("you are in the control group! Relax and enjoy the ride");
}
};);
// I tend not to like 'register', but it might be the right way of doing things?
experiment.cleanup(function(){this.snapshot('some.branch')});
experiment.cleanup(function(){this.survey(['q1','This extension ruled, right?'])});
// send it off!
exports.experiment = experiment
/*****************************
users: experiment writers, who are:
- ui engineers
- add-on writers
what's in an experiment:
_handlers: all watched and by hand handlers
_cleanup: cleanup functions, if you need to go fix them.
by default, you get 'unregister handlers' and 'uninstall_extensions'
for free, here.
_metadata: cleaned up / guarded version of metadata
_extensions: registered extensions?
lots of methods, including many from current TP baseClasses:
.watch
.record <- direct write to bd
*****************************/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment