Created
December 7, 2012 10:50
-
-
Save detj/4232460 to your computer and use it in GitHub Desktop.
Piping Backbone Methods
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
;(function() { | |
var _fetch = Backbone.Collection.prototype.fetch; | |
var _reset = Backbone.Collection.prototype.reset; | |
_.extend(Backbone.Collection.prototype, { | |
fetching: false | |
}); | |
Backbone.Collection.prototype.fetch = function(options) { | |
this.fetching = true; | |
console.log('Fetching on'); | |
_fetch.call(this, options); | |
} | |
Backbone.Collection.prototype.reset = function(model, options) { | |
if (this.fetching) this.fetching = false; | |
console.log('Fetching off'); | |
_reset.apply(this, [model, options]); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment