Skip to content

Instantly share code, notes, and snippets.

@tedkulp
Created January 22, 2014 16:50
Show Gist options
  • Save tedkulp/8562352 to your computer and use it in GitHub Desktop.
Save tedkulp/8562352 to your computer and use it in GitHub Desktop.
How we add common functionality to different extended Marionette classes.
Module.WreqrMixin = function(obj) {
return _.extend(obj, {
setupWreqr: function() {
var _this = this;
this.reqres = new Backbone.Wreqr.RequestResponse();
this.commands = new Backbone.Wreqr.Commands();
this.request = function() {
return _this.reqres.request.apply(_this.reqres, arguments);
};
this.hasRequestHandler = function(name) {
return _this.reqres.hasHandler(name);
};
this.setRequestHandler = function() {
_this.reqres.setHandler.apply(_this.reqres, arguments);
return _this;
};
this.execute = function() {
return _this.commands.execute.apply(_this.commands, arguments);
};
this.hasExecuteHandler = function(name) {
return _this.commands.hasHandler(name);
};
this.setExecuteHandler = function() {
_this.commands.setHandler.apply(_this.commands, arguments);
return _this;
};
return this;
},
}).setupWreqr.apply(obj);
};
Module.ListView = Marionette.ItemView.extend({
constructor: function(options) {
Marionette.ItemView.prototype.constructor.apply(this, arguments);
Module.WreqrMixin(this);
return this;
},
});
Module.LayoutView = Marionette.Layout.extend({
constructor: function(options) {
Marionette.Layout.prototype.constructor.apply(this, arguments);
Module.WreqrMixin(this);
return this;
},
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment