Added queue flag to $.Callbacks. Unit tests added (more to come).

1.7/callbacks
jaubourg 2011-05-26 18:38:34 +01:00
parent 0c9c9fb3cf
commit 950da8ae7f
2 changed files with 7 additions and 0 deletions

View File

@ -34,6 +34,9 @@ function createFlags( flags ) {
* after the list has been fired right away with the latest "memorized"
* values (like a Deferred)
*
* queue: only first callback in the list is called each time the list is fired
* (cannot be used in conjunction with memory)
*
* unique: will ensure a callback can only be added once (no duplicate in the list)
*
* relocate: like "unique" but will relocate the callback at the end of the list
@ -112,6 +115,9 @@ jQuery.Callbacks = function( flags, filter ) {
if ( list[ firingIndex ][ 1 ].apply( context, args ) === false && flags.stopOnFalse ) {
memory = true; // Mark as halted
break;
} else if ( flags.queue ) {
list.splice( firingIndex, 1 );
break;
}
}
firing = false;

View File

@ -19,6 +19,7 @@ var output,
"relocate": "XABC X XAABC X XBB X XBA X",
"stopOnFalse": "XABC X XABCABCC X XBB X XA X",
"addAfterFire": "XAB X XABCAB X XBB X XABA X",
"queue": "XA X XB X XB X XA X",
"once memory": "XABC XABC X XA X XA XABA XC",
"once unique": "XABC X X X X X XAB X",
"once relocate": "XABC X X X X X XBA X",