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

This commit is contained in:
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" * after the list has been fired right away with the latest "memorized"
* values (like a Deferred) * 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) * 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 * 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 ) { if ( list[ firingIndex ][ 1 ].apply( context, args ) === false && flags.stopOnFalse ) {
memory = true; // Mark as halted memory = true; // Mark as halted
break; break;
} else if ( flags.queue ) {
list.splice( firingIndex, 1 );
break;
} }
} }
firing = false; firing = false;

View file

@ -19,6 +19,7 @@ var output,
"relocate": "XABC X XAABC X XBB X XBA X", "relocate": "XABC X XAABC X XBB X XBA X",
"stopOnFalse": "XABC X XABCABCC X XBB X XA X", "stopOnFalse": "XABC X XABCABCC X XBB X XA X",
"addAfterFire": "XAB X XABCAB X XBB X XABA 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 memory": "XABC XABC X XA X XA XABA XC",
"once unique": "XABC X X X X X XAB X", "once unique": "XABC X X X X X XAB X",
"once relocate": "XABC X X X X X XBA X", "once relocate": "XABC X X X X X XBA X",