testable 'global' vent - musing on easy dependency injection
This file contains 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
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