Skip to content

Instantly share code, notes, and snippets.

@lsmith
Created May 16, 2013 22:24
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 lsmith/5595595 to your computer and use it in GitHub Desktop.
Save lsmith/5595595 to your computer and use it in GitHub Desktop.
var ops = [], i, len;
for (i = 0, len = models.length; i < len; ++i) {
ops.push(new Y.Promise(function (resolve, reject) {
Y.io('save-my-stuff.php', {
data: models[i].toJSON(),
on: {
success: function (id, xhr) {
// Maybe you want to JSON parse the responseText first?
// Maybe you don't care about the response beyond it being 200?
resolve(xhr.responseText);
},
failure: function () {
reject(new Error("IO error"));
}
}
});
});
}
Y.batch.apply(Y, ops).then(
function () {
console.log('All models saved');
},
function (reason) {
console.log('Uh oh. Something went wrong: ' + reason);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment