Skip to content

Instantly share code, notes, and snippets.

@erichiggins
Created March 8, 2013 02:39
Show Gist options
  • Save erichiggins/5113816 to your computer and use it in GitHub Desktop.
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.
// 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