From 4df0c82807fe094d5262053c5bd9fa729d308543 Mon Sep 17 00:00:00 2001 From: Kevin Crawford Date: Tue, 14 Oct 2014 13:00:56 -0700 Subject: [PATCH] refactor(sync): add $http promise arguments to options 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. --- ng-backbone.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/ng-backbone.js b/ng-backbone.js index 171d74b..04af64f 100644 --- a/ng-backbone.js +++ b/ng-backbone.js @@ -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); }