aboutsummaryrefslogtreecommitdiffstats
path: root/src/deferred.js
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2011-10-11 20:23:56 -0400
committerjaubourg <j@ubourg.net>2011-10-11 20:23:56 -0400
commitd29182e8d00b08def0f37fe7e77d9836e39b83a8 (patch)
treedd38d2e32abc6d0a2d369000bfc2b6bc13e9d335 /src/deferred.js
parent511c9fe763bac171bb6ac3ac0a77c425da8b3112 (diff)
downloadjquery-d29182e8d00b08def0f37fe7e77d9836e39b83a8.tar.gz
jquery-d29182e8d00b08def0f37fe7e77d9836e39b83a8.zip
Removes isPending and introduces state as a means to retrieve the Deferred/Promise state. Unit tests amended.
Diffstat (limited to 'src/deferred.js')
-rw-r--r--src/deferred.js18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/deferred.js b/src/deferred.js
index 9e5f5110a..457bc521f 100644
--- a/src/deferred.js
+++ b/src/deferred.js
@@ -9,6 +9,7 @@ jQuery.extend({
var doneList = jQuery.Callbacks( "once memory" ),
failList = jQuery.Callbacks( "once memory" ),
progressList = jQuery.Callbacks( "memory" ),
+ state = "pending",
lists = {
resolve: doneList,
reject: failList,
@@ -19,11 +20,13 @@ jQuery.extend({
fail: failList.add,
progress: progressList.add,
+ state: function() {
+ return state;
+ },
+
+ // Deprecated
isResolved: doneList.fired,
isRejected: failList.fired,
- isPending: function() {
- return !progressList.locked();
- },
then: function( doneCallbacks, failCallbacks, progressCallbacks ) {
deferred.done( doneCallbacks ).fail( failCallbacks ).progress( progressCallbacks );
@@ -78,9 +81,12 @@ jQuery.extend({
deferred[ key + "With" ] = lists[ key ].fireWith;
}
- // Handle lists exclusiveness
- deferred.done( failList.disable, progressList.lock )
- .fail( doneList.disable, progressList.lock );
+ // Handle state
+ deferred.done( function() {
+ state = "resolved";
+ }, failList.disable, progressList.lock ).fail( function() {
+ state = "rejected";
+ }, doneList.disable, progressList.lock );
// Call given func if any
if ( func ) {