public
Created

testable 'global' vent - musing on backbone marionette

  • Download Gist
testable_vent.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
View = Backbone.View.extend({
initialize: function(opts) {
View.__super__.initialize.apply(this,arguments);
if(opts.vent) this.vent = opts.vent;
},
ventOn: function(evt,method,context) {
(this.vent || window.App.vent).on(evt,method,context);
},
ventOff: function(evt,method,context) {
(this.vent || window.App.vent).off(evt,method,context);
}
// or if you're ok with this.vent().on()
vent: function() {
return this.vent || window.App.vent;
}
})
 
 
// in production
App = new App
App.vent = myGlobal
 
// in test
toTest = new View({vent: mockVent});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.