Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
testable 'global' vent - musing on easy dependency injection
var View = Backbone.View.extend({
constructor: function(opts) {
this.vent = (opts && opts.vent) || window.vent;
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