Skip to content

Commit

Permalink
rejecting with the response object
Browse files Browse the repository at this point in the history
  • Loading branch information
spacenick committed Jun 14, 2013
1 parent a059a01 commit 81c0f04
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Ultra lightweight & seamless Backbone.sync override to work with promises.

Just include the script after backbone. And you'll be able to do :

‘‘‘javascript
var myModel = new Backbone.Model();
myModel.url = "https://my.balling-api.com/whatever";

myModel.fetch().then(function(data){
console.log(data);
// data is RAW json
// however, classic "callback" is still called seamlessly so:
// data.attribute == myModel.get('attribute')
},
function(response){
console.log(response.statusText);
});

‘‘‘
2 changes: 1 addition & 1 deletion backbone-sync-deferred.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
// Override error
options.error = function(model, response, options) {
if (origError) origError(model, response, options);
return deferred.reject(response.responseText);
return deferred.reject(response);
};

origSync(method, model, options);
Expand Down

0 comments on commit 81c0f04

Please sign in to comment.