Created
February 9, 2012 23:12
-
-
Save rgrove/1784146 to your computer and use it in GitHub Desktop.
Simple XHR model sync with XML data
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
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