Skip to content

Instantly share code, notes, and snippets.

@matthewmueller
Created March 1, 2013 23:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewmueller/5068886 to your computer and use it in GitHub Desktop.
Save matthewmueller/5068886 to your computer and use it in GitHub Desktop.
Sync.prototype.sync = function(fn) {
var self = this,
batch = new Batch,
tag = this.tag;
Note.all(function(err, notes) {
notes = notes.select(function(note) { return ~note.tags.indexOf(tag); })
if(!notes.length) return fn();
notes.each(function(note) {
var action = (note.deleted) ? 'remove' : 'update';
batch.push(function(done) { self[action](note, done); });
});
});
batch.end(fn);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment