Created
July 15, 2013 09:14
-
-
Save jboulhous/5998577 to your computer and use it in GitHub Desktop.
beforeSync, afterSync for backbone Entities.
https://github.com/eventray/backbone.synctracker
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
| // https://github.com/eventray/backbone.synctracker | |
| (function() { | |
| 'use strict'; | |
| //Save a reference to the global object (`window` in the browser, `exports` | |
| // on the server). | |
| var root = this; | |
| var ajaxSync = Backbone.sync; | |
| Backbone.sync = function(method, model, options, error) { | |
| var me = this; | |
| this.trigger('before:sync'); | |
| if (this.hasOwnProperty('beforeSync')) { | |
| this.beforeSync(); | |
| } | |
| this.fetched = false; | |
| var deferred = ajaxSync.call(this, method, model, options, error); | |
| deferred.then(function() { | |
| me.fetched = true; | |
| me.trigger('after:sync'); | |
| if (me.hasOwnProperty('afterSync')) { | |
| me.afterSync(); | |
| } | |
| }); | |
| return deferred; | |
| } | |
| }).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment