Fixes repeatable callbacks list with memory disabling. Unit tests for Deferreds updated.
This commit is contained in:
parent
1ed70e056d
commit
9edc3d4f39
2 changed files with 35 additions and 34 deletions
|
@ -100,6 +100,33 @@ jQuery.Callbacks = function( flags, filter ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
fire = function( context, args ) {
|
||||||
|
args = args || [];
|
||||||
|
memory = !flags.memory || [ context, args ];
|
||||||
|
firing = true;
|
||||||
|
firingIndex = firingStart || 0;
|
||||||
|
firingStart = 0;
|
||||||
|
firingLength = list.length;
|
||||||
|
for ( ; list && firingIndex < firingLength; firingIndex++ ) {
|
||||||
|
if ( list[ firingIndex ][ 1 ].apply( context, args ) === false && flags.stopOnFalse ) {
|
||||||
|
memory = true; // Mark as halted
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
firing = false;
|
||||||
|
if ( list ) {
|
||||||
|
if ( !flags.once ) {
|
||||||
|
if ( stack && stack.length ) {
|
||||||
|
memory = stack.shift();
|
||||||
|
object.fireWith( memory[ 0 ], memory[ 1 ] );
|
||||||
|
}
|
||||||
|
} else if ( memory === true ) {
|
||||||
|
object.disable();
|
||||||
|
} else {
|
||||||
|
list = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
object = {
|
object = {
|
||||||
// Add a callback or a collection of callbacks to the list
|
// Add a callback or a collection of callbacks to the list
|
||||||
add: function() {
|
add: function() {
|
||||||
|
@ -116,10 +143,8 @@ jQuery.Callbacks = function( flags, filter ) {
|
||||||
// we should call right away, unless previous
|
// we should call right away, unless previous
|
||||||
// firing was halted (stopOnFalse)
|
// firing was halted (stopOnFalse)
|
||||||
} else if ( memory && memory !== true ) {
|
} else if ( memory && memory !== true ) {
|
||||||
var tmp = memory;
|
|
||||||
memory = undefined;
|
|
||||||
firingStart = length;
|
firingStart = length;
|
||||||
object.fireWith( tmp[ 0 ], tmp[ 1 ] );
|
fire( memory[ 0 ], memory[ 1 ] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
@ -197,31 +222,7 @@ jQuery.Callbacks = function( flags, filter ) {
|
||||||
stack.push( [ context, args ] );
|
stack.push( [ context, args ] );
|
||||||
}
|
}
|
||||||
} else if ( !( flags.once && memory ) ) {
|
} else if ( !( flags.once && memory ) ) {
|
||||||
args = args || [];
|
fire( context, args );
|
||||||
memory = !flags.memory || [ context, args ];
|
|
||||||
firing = true;
|
|
||||||
firingIndex = firingStart || 0;
|
|
||||||
firingStart = 0;
|
|
||||||
firingLength = list.length;
|
|
||||||
for ( ; list && firingIndex < firingLength; firingIndex++ ) {
|
|
||||||
if ( list[ firingIndex ][ 1 ].apply( context, args ) === false && flags.stopOnFalse ) {
|
|
||||||
memory = true; // Mark as halted
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
firing = false;
|
|
||||||
if ( list ) {
|
|
||||||
if ( !flags.once ) {
|
|
||||||
if ( stack && stack.length ) {
|
|
||||||
memory = stack.shift();
|
|
||||||
object.fireWith( memory[ 0 ], memory[ 1 ] );
|
|
||||||
}
|
|
||||||
} else if ( memory === true ) {
|
|
||||||
object.disable();
|
|
||||||
} else {
|
|
||||||
list = [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -39,7 +39,7 @@ jQuery.each( [ "", " - new operator" ], function( _, withNew ) {
|
||||||
createDeferred( function( defer ) {
|
createDeferred( function( defer ) {
|
||||||
var checked = 0;
|
var checked = 0;
|
||||||
defer.progress(function( value ) {
|
defer.progress(function( value ) {
|
||||||
strictEqual( value, checked, "Progress: right value (" + value + ") received" )
|
strictEqual( value, checked, "Progress: right value (" + value + ") received" );
|
||||||
});
|
});
|
||||||
for( checked = 0; checked < 3 ; checked++ ) {
|
for( checked = 0; checked < 3 ; checked++ ) {
|
||||||
defer.ping( checked );
|
defer.ping( checked );
|
||||||
|
@ -146,8 +146,8 @@ test( "jQuery.Deferred.pipe - filtering (progress)", function() {
|
||||||
|
|
||||||
defer.ping( 2, 3 );
|
defer.ping( 2, 3 );
|
||||||
|
|
||||||
strictEqual( value1, 2, "first reject value ok" );
|
strictEqual( value1, 2, "first progress value ok" );
|
||||||
strictEqual( value2, 3, "second reject value ok" );
|
strictEqual( value2, 3, "second progress value ok" );
|
||||||
strictEqual( value3, 6, "result of filter ok" );
|
strictEqual( value3, 6, "result of filter ok" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -236,8 +236,8 @@ test( "jQuery.Deferred.pipe - deferred (progress)", function() {
|
||||||
|
|
||||||
defer.ping( 2, 3 );
|
defer.ping( 2, 3 );
|
||||||
|
|
||||||
strictEqual( value1, 2, "first reject value ok" );
|
strictEqual( value1, 2, "first progress value ok" );
|
||||||
strictEqual( value2, 3, "second reject value ok" );
|
strictEqual( value2, 3, "second progress value ok" );
|
||||||
strictEqual( value3, 6, "result of filter ok" );
|
strictEqual( value3, 6, "result of filter ok" );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -284,7 +284,7 @@ test( "jQuery.when" , function() {
|
||||||
|
|
||||||
test("jQuery.when - joined", function() {
|
test("jQuery.when - joined", function() {
|
||||||
|
|
||||||
expect(50);
|
expect(53);
|
||||||
|
|
||||||
var deferreds = {
|
var deferreds = {
|
||||||
value: 1,
|
value: 1,
|
||||||
|
|
Loading…
Reference in a new issue