Skip to content

Commit

Permalink
refactor(sync): add $http promise arguments to options
Browse files Browse the repository at this point in the history
Backbone methods that internally use Backbone.sync (like fetch, create, save) accept error and success callback functions with the arguments `collection` (or `model`), `response`, `options`.

In normal Backbone.js using $.ajax, options.xhr gets set to a jqXHR object. Although $http doesn't give us an XHR object to use, this makes the differing APIs a little bit closer.
  • Loading branch information
Kevin Crawford committed Oct 14, 2014
1 parent 6bef93e commit 4df0c82
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions ng-backbone.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,25 @@
params.params = options.data;
}

var xhr = options.xhr = ajax(_.extend(params, options)).
success(function(data) {
var xhr = ajax(_.extend(params, options)).
success(function(data, status, headers, config) {
options.xhr = {
status: status,
headers: headers,
config: config
};

if (!isUndefined(options.success) && _.isFunction(options.success)) {
options.success(data);
}
}).
error(function(data) {
error(function(data, status, headers, config) {
options.xhr = {
status: status,
headers: headers,
config: config
};

if (!isUndefined(options.error) && _.isFunction(options.error)) {
options.error(data);
}
Expand Down

0 comments on commit 4df0c82

Please sign in to comment.