Last active
December 14, 2015 00:39
-
-
Save camshaft/5001026 to your computer and use it in GitHub Desktop.
experiment ideas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Module dependencies | |
| */ | |
| var express = require("express") | |
| , pivot = require("pivot"); | |
| var app = module.exports = express(); | |
| /** | |
| * Experiments | |
| */ | |
| function loginButtonColor(req, res, next) { | |
| // Change the login button color | |
| res.feature("loginButtonColor", "red", function(){ | |
| res.locals.loginButtonColor = "red"; | |
| }); | |
| res.feature("loginButtonColor", "blue", function(){ | |
| res.locals.loginButtonColor = "blue"; | |
| }); | |
| next(); | |
| } | |
| function userData(req, res, next) { | |
| res.feature("asyncExample", "api1", function(done){ | |
| // Make api1 call | |
| res.locals.user = user; | |
| done(); | |
| }); | |
| res.feature("asyncExample", "api2", function(done){ | |
| // Make api1 call | |
| res.locals.user = user; | |
| done(); | |
| }); | |
| next(); | |
| } | |
| var experiments = pivot(); | |
| experiments.use(loginButtonColor); | |
| experiments.use(userData); | |
| /** | |
| * Configure our app | |
| */ | |
| app.configure(function(){ | |
| app.use(experiments); | |
| }); | |
| app.get("/", function(req, res, next){ | |
| res.render("index"); | |
| }); | |
| app.get("/ad-hoc", function(req, res, next) { | |
| // We can do ad-hoc features | |
| res.feature("welcomeMessage", "test1", function() { | |
| res.locals.welcomeMessage = "Hello!"; | |
| }); | |
| res.feature("welcomeMessage", "test2", function() { | |
| res.locals.welcomeMessage = "Welcome Friend!"; | |
| }); | |
| res.render("ad-hoc"); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Module dependencies | |
| */ | |
| var express = require("express") | |
| , pivot = require("pivot"); | |
| var app = module.exports = express(); | |
| /** | |
| * Experiments | |
| */ | |
| function loginButtonColor(req, res, next) { | |
| // Change the login button color | |
| res.feature("loginButtonColor", function(button){ | |
| button.on("red", function(){ | |
| res.locals.loginButtonColor = "red"; | |
| }); | |
| button.on("blue", function(){ | |
| res.locals.loginButtonColor = "red"; | |
| }); | |
| }); | |
| } | |
| function logoutButtonColor(req, res, next) { | |
| // Change the login button color | |
| res.feature("logoutButtonColor", function(button){ | |
| button.on("red", function(){ | |
| res.locals.logoutButtonColor = "red"; | |
| }); | |
| button.on("blue", function(){ | |
| res.locals.logoutButtonColor = "red"; | |
| }); | |
| }); | |
| } | |
| function userData(req, res, next) { | |
| res.feature("asyncExample", function(userData){ | |
| userData.on("api1", function(done){ | |
| // Make api1 call | |
| res.locals.user = user; | |
| done(); | |
| }); | |
| userData.on("api2", function(done){ | |
| // Make api2 call | |
| res.locals.user = userFromApi; | |
| done(); | |
| }); | |
| }); | |
| next(); | |
| } | |
| var experiments = pivot(); | |
| experiments.use(loginButtonColor); | |
| experiments.use(logoutButtonColor); | |
| experiments.use(userData); | |
| /** | |
| * Configure our app | |
| */ | |
| app.configure(function(){ | |
| app.use(experiments); | |
| app.use("/experiments", experiments.ui); | |
| }); | |
| app.get("/", function(req, res, next){ | |
| res.render("index"); | |
| }); | |
| app.get("/ad-hoc", function(req, res, next) { | |
| // We can do ad-hoc features | |
| res.feature("ad-hoc", function(adHoc) { | |
| adHoc.on("test1", function() { | |
| res.locals.welcomeMessage = "Hello!"; | |
| }); | |
| adHoc.on("test2", function() { | |
| res.locals.welcomeMessage = "Welcome Friend!"; | |
| }); | |
| }); | |
| res.render("ad-hoc"); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function embedded(req, res, next) { | |
| // Change the experience based on their group | |
| res.feature("betaUser", function(userType){ | |
| userType.on("beta", "beta", function(){ | |
| // switch a feature for beta users | |
| res.feature("betaFeature", function(betaFeature) { | |
| betaFeature.on("test1", function() { | |
| res.locals.count = 1; | |
| }); | |
| betaFeature.on("test2", function() { | |
| res.locals.count = -1; | |
| }); | |
| }); | |
| }); | |
| userType.on("non-beta", "*", function(){ | |
| res.locals.count = 0; | |
| }); | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="login"> | |
| <% feature("loginButtonColor", "red", function() { %> | |
| <button class="btn btn-red">Login</button> | |
| <% }); %> | |
| <% feature("loginButtonColor", "blue", function() { %> | |
| <button class="btn btn-blue">Login</button> | |
| <% }); %> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .login | |
| - feature("loginButtonColor", "red", function(){ | |
| button.btn.btn-red Login | |
| - }); | |
| - feature("loginButtonColor", "blue", function(){ | |
| button.btn.btn-blue Login | |
| - }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="login"> | |
| <% @feature "loginButtonColor", (exp)-> %> | |
| <% exp.on "red", ()-> %> | |
| <button class="btn btn-red">Login</button> | |
| <% end %> | |
| <% exp.on "blue", ()-> %> | |
| <button class="btn btn-blue">Login</button> | |
| <% end %> | |
| <% end %> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="login"> | |
| <% feature("loginButtonColor", function(exp) { %> | |
| <% exp.on("red", function(){%> | |
| <button class="btn btn-red">Login</button> | |
| <% }); %> | |
| <% exp.on("blue", function(){%> | |
| <button class="btn btn-blue">Login</button> | |
| <% }); %> | |
| <% }); %> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .login | |
| - feature("loginButtonColor", function(exp){ | |
| - exp.on("red", function(){ | |
| button.btn.btn-red Login | |
| - }); | |
| - exp.on("blue", function(){ | |
| button.btn.btn-blue Login | |
| - }); | |
| - }); |
Author
Author
now that i look at it, it would be impossible for the alt syntax to work :(
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
depending on how some of these rendering engines work, the alternative syntax wouldn't work since pivot would have to scan the entire file and look up all of the variants registered. I like the first syntax since it contains the variants to a limited scope.