Skip to content
This repository has been archived by the owner on Jun 26, 2022. It is now read-only.

Commit

Permalink
Remove Backbone.resolveDeferred. Closes gh-40.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Nov 1, 2013
1 parent 12b4a76 commit 60698c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
15 changes: 8 additions & 7 deletions lib/dom-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ utils.ajax = (function() {
(xhr.status === 0 && window.location.protocol === 'file:')
};

var end = function(xhr, options, promise) {
var end = function(xhr, options, deferred) {
return function() {
if (xhr.readyState !== 4) return;

Expand All @@ -54,12 +54,11 @@ utils.ajax = (function() {
// Check for validity.
if (isValid(xhr)) {
if (options.success) options.success(data);
if (promise) Backbone.resolveDeferred(promise, true, [data, xhr]);
if (deferred) deferred.resolve(data);
} else {
var error = new Error('Server responded with a status of ' + status);
error.code = status;
if (options.error) options.error(xhr, status, error);
if (promise) Backbone.resolveDeferred(promise, false, [xhr]);
if (deferred) deferred.reject(xhr);
}
}
};
Expand All @@ -69,14 +68,16 @@ utils.ajax = (function() {
if (options.method == null) options.method = 'GET';

var xhr = new XMLHttpRequest();
var promise = Backbone.Deferred && Backbone.Deferred();
var deferred = Backbone.Deferred && Backbone.Deferred();

if (options.credentials) options.withCredentials = true;
xhr.addEventListener('readystatechange', end(xhr, options, promise));
xhr.addEventListener('readystatechange', end(xhr, options, deferred));
xhr.open(options.method, options.url, true);
if (options.headers) for (var key in options.headers) {
xhr.setRequestHeader(key, options.headers[key]);
}
xhr.send(options.data);
return promise;

return deferred ? deferred.promise : undefined;
};
})();
6 changes: 1 addition & 5 deletions lib/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ Backbone.ajax = Backbone.$ ? function() {
return Backbone.$.ajax.apply(Backbone.$, arguments);
} : utils.ajax;

Backbone.Deferred = Backbone.$ ? function() {
if (Backbone.$) Backbone.Deferred = function() {
return new Backbone.$.Deferred();
} : null;

Backbone.resolveDeferred = function(deferred, isResolved, args) {
return null;
};

6 comments on commit 60698c2

@paulmillr
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@akre54 are you cool with that? gonna release 0.4.1

@akre54
Copy link
Contributor

@akre54 akre54 commented on 60698c2 Nov 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

This way the dev just overwrites Backbone.Deferred with q, when, davy, etc., right?

@paulmillr
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

@akre54
Copy link
Contributor

@akre54 akre54 commented on 60698c2 Nov 1, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to implement the rest of jashkenas/backbone#2489 too?

@paulmillr
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's leave as-is for now

@akre54
Copy link
Contributor

@akre54 akre54 commented on 60698c2 Nov 1, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.