Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

testable 'global' vent - musing on easy dependency injection

View testable_vent.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
var View = Backbone.View.extend({
constructor: function(opts) {
this.vent = (opts && opts.vent) || window.vent;
 
Backbone.View.apply(this,arguments);
}
});
 
function Vent() {}
Vent.prototype = _.extend({},Backbone.Events);
 
// in production
 
window.vent = new Vent
var productionView = new View(); // implicit app vent
 
// in test
toTest = new View({vent: mockVent});
 
// in a sub-system with a specific vent
var subVent = new Vent
var subA = new View({vent: subVent});
var subB = new View({vent: subVent});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.