Skip to content
Permalink
Browse files

Merge branch '1.8-deferred-optimize2' of git://github.com/gibson042/j…

…query into PR754
  • Loading branch information...
jaubourg committed Apr 28, 2012
2 parents 5fc8d9e + a25721a commit 13f4f5adc25543b8c243555fa5a9eb9682088168
Showing with 11 additions and 8 deletions.
  1. +11 −8 src/deferred.js
@@ -7,9 +7,9 @@ jQuery.extend({

Deferred: function( func ) {
var tuples = [
// action, add listener, listener list
[ "resolve", "done", jQuery.Callbacks("once memory") ],
[ "reject", "fail", jQuery.Callbacks("once memory") ],
// action, add listener, listener list, final state
[ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ],
[ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ],
[ "notify", "progress", jQuery.Callbacks("memory") ]
],
state = "pending",
@@ -59,19 +59,22 @@ jQuery.extend({

// Add list-specific methods
jQuery.each( tuples, function( i, tuple ) {
var list = tuple[ 2 ], stateString;
var list = tuple[ 2 ],
stateString = tuple[ 3 ];

// promise[ done | fail | progress ] = list.add
promise[ tuple[1] ] = list.add;

// Handle state
if ( i < 2 ) {
stateString = tuple[ 0 ].replace( /e?$/, "ed" );
list.add(function() {
// state = [ resolved | rejected ]
state = stateString;
tuples[ i ^ 1 ][ 2 ].disable();
tuples[ 2 ][ 2 ].lock();
});

// [ reject_list | resolve_list ].disable; progress_list.lock
}, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock );

// [ isResolved | isRejected ] = [ resolve_list | reject_list ].fired
promise[ "isR" + stateString.substr( 1 ) ] = list.fired;
}

0 comments on commit 13f4f5a

Please sign in to comment.
You can’t perform that action at this time.