Skip to content

Instantly share code, notes, and snippets.

@rgrove
Created February 9, 2012 23:12
Show Gist options
  • Save rgrove/1784146 to your computer and use it in GitHub Desktop.
Save rgrove/1784146 to your computer and use it in GitHub Desktop.
Simple XHR model sync with XML data
model.load({url: 'http://www.company.com/somefile.xml'}, function (err, response) {
Y.log("Model load " + response);
});
// Custom sync layer.
sync: function (action, options, callback) {
switch (action) {
case 'read':
Y.io(options.url, {
on: {
failure: function () {
callback(Error('XHR request failed'));
},
success: function (conn, res) {
callback(null, res.responseXML);
}
}
});
return;
default:
Y.log("Model sync action default");
callback(Error('Invalid action'));
}
},
// Custom response parser.
parse: function (xml) {
// TODO: turn the xml object into an object that represents this model's
// attributes.
Y.log("Model parse " + xml);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment