Created
March 8, 2013 02:39
-
-
Save erichiggins/5113816 to your computer and use it in GitHub Desktop.
Backbone mixin that maintains a timestamp for the last successful "sync" event. This can be used on both Models and Collections.
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
// Last Sync timestamp mixin. Works for Models and Collections. | |
var LastSync = { | |
// Update lastSync with current timestamp. | |
_timestampSync: function() { | |
this.lastSync = new Date(); | |
}, | |
// Note: Call LastSync.initialize.apply(this) from the Model/Collection .initialize. | |
initialize: function() { | |
// Setup lastSync to timestamp sync events. | |
this.lastSync = null; | |
// Events. | |
this.on('sync', this._timestampSync, this); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment