Skip to content

Instantly share code, notes, and snippets.

@timruffles
Last active October 6, 2015 20:18
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save timruffles/3047279 to your computer and use it in GitHub Desktop.
testable 'global' vent - musing on easy dependency injection
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