Skip to content

Commit 950da8a

Browse files
committed
Added queue flag to $.Callbacks. Unit tests added (more to come).
1 parent 0c9c9fb commit 950da8a

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/callbacks.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ function createFlags( flags ) {
3434
* after the list has been fired right away with the latest "memorized"
3535
* values (like a Deferred)
3636
*
37+
* queue: only first callback in the list is called each time the list is fired
38+
* (cannot be used in conjunction with memory)
39+
*
3740
* unique: will ensure a callback can only be added once (no duplicate in the list)
3841
*
3942
* relocate: like "unique" but will relocate the callback at the end of the list
@@ -112,6 +115,9 @@ jQuery.Callbacks = function( flags, filter ) {
112115
if ( list[ firingIndex ][ 1 ].apply( context, args ) === false && flags.stopOnFalse ) {
113116
memory = true; // Mark as halted
114117
break;
118+
} else if ( flags.queue ) {
119+
list.splice( firingIndex, 1 );
120+
break;
115121
}
116122
}
117123
firing = false;

test/unit/callbacks.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var output,
1919
"relocate": "XABC X XAABC X XBB X XBA X",
2020
"stopOnFalse": "XABC X XABCABCC X XBB X XA X",
2121
"addAfterFire": "XAB X XABCAB X XBB X XABA X",
22+
"queue": "XA X XB X XB X XA X",
2223
"once memory": "XABC XABC X XA X XA XABA XC",
2324
"once unique": "XABC X X X X X XAB X",
2425
"once relocate": "XABC X X X X X XBA X",

0 commit comments

Comments
 (0)