Created
July 23, 2012 19:10
-
-
Save sumitngupta/3165516 to your computer and use it in GitHub Desktop.
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
| // Patch Model and Collection. | |
| _.each(["Model", "Collection"], function(name) { | |
| // Cache Backbone constructor. | |
| var ctor = Backbone[name]; | |
| // Cache original fetch. | |
| var fetch = ctor.prototype.fetch; | |
| // Override the fetch method to emit a fetch event. | |
| ctor.prototype.fetch = function() { | |
| // Trigger the fetch event on the instance. | |
| this.trigger("fetch", this); | |
| this._lastFetchedAt = new Date(); | |
| // Pass through to original fetch. | |
| return fetch.apply(this, arguments); | |
| }; | |
| ctor.prototype.hasFetched = function () { | |
| return !!this._lastFetchedAt; | |
| }; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment