Last active
December 10, 2015 15:18
-
-
Save thegrubbsian/4453593 to your computer and use it in GitHub Desktop.
Backbone Extensions Stuff
This file contains hidden or 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
Backbone.Base = function() { | |
this.initialize.apply(this, arguments); | |
}; | |
Backbone.Base.extend = Backbone.Model.extend; | |
_.extend(Backbone.Base.prototype, Backbone.Events, { | |
initialize: function() {} | |
}); |
This file contains hidden or 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
(function() { | |
Backbone.Events.proxyEvents = function(source, namespace) { | |
var _self = this; | |
if (!_self.__proxySources) { _self.__proxySources = []; } | |
if (_(_self.__proxySources).include(source)) { return; } | |
_self.__proxySources.push(source); | |
var handler = function(evt) { | |
var args = Array.prototype.slice.apply(arguments).splice(1); | |
if (namespace) { evt = namespace + ":" + evt; } | |
args.unshift(evt); | |
_self.trigger.apply(_self, arguments); | |
}; | |
source.on("all", handler); | |
return this; | |
}; | |
Backbone.Events.rebind = function(evt, func) { | |
this.off(evt, func); | |
this.on(evt, func); | |
}; | |
_([Backbone.Model, Backbone.Collection, Backbone.View, | |
Backbone.Router, Backbone.Base]) | |
.each(function(klass) { | |
klass.prototype.proxyEvents = Backbone.Events.proxyEvents; | |
klass.prototype.rebind = Backbone.Events.rebind; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment