-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,14 @@ var methodMap = { | |
|
||
// Set the default implementation of `Backbone.ajax` to proxy through to `$`. | ||
// Override this if you'd like to use a different library. | ||
Backbone.ajax = function() { | ||
Backbone.ajax = Backbone.$ ? function() { | ||
return Backbone.$.ajax.apply(Backbone.$, arguments); | ||
} : utils.ajax; | ||
|
||
Backbone.Deferred = Backbone.$ ? function() { | ||
This comment has been minimized.
Sorry, something went wrong. |
||
return new Backbone.$.Deferred(); | ||
} : null; | ||
|
||
Backbone.resolveDeferred = function(deferred, isResolved, args) { | ||
This comment has been minimized.
Sorry, something went wrong.
akre54
Contributor
|
||
return null; | ||
}; |
2 comments
on commit 3e22ea1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ivivski: as I understand it, it's more like
function deferred() {
var resolve, reject, p = new Promise(function(res, rej) {
resolve = res;
reject = rej;
});
return {
promise: p,
resolve: function (v) { resolve(v) },
reject: function (e) { reject(e) }
}
}
Since promises should never leak their resolve / reject functions when passed around. For deferreds it's ok though.
Some implementations like q
have global resolve/reject fns (more like davy
), when
passes back with a resolver fn on the deferred itself. Ember's RSVP is the closest to the example here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was an example of how do you do a deferred with Davy
. I don't really like the idea of a callback based promises
. It's like "Do you want to extract callbacks from your functions? Create a promise, but give it a callback" LOL. And you have to add another "magic" object called Deferred, that exposes all the resolve
/reject
methods. Two layers of abstraction for one simple thing is an "enterprise bullshit". You have a promise
with three methods then
/resolve
/reject
. With this approach deferred object becomes useless, 'cause you already have access to everything you need. jQuery uses deferreds 'cause the think we are all stupid and don't understand what we are doing, so it's safer to encapsulate this things.
That way it can be overridden if someone wants to use Q, when, etc.
See jashkenas/backbone#2489