🌐 AI搜索 & 代理 主页
Skip to content

Commit 9d822bc

Browse files
authored
Callbacks: Prevent add() from unlocking with-memory lists
Fixes gh-3469 Closes gh-3470
1 parent 14b393d commit 9d822bc

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/callbacks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jQuery.Callbacks = function( options ) {
6969
fire = function() {
7070

7171
// Enforce single-firing
72-
locked = options.once;
72+
locked = locked || options.once;
7373

7474
// Execute callbacks for all pending executions,
7575
// respecting firingIndex overrides and runtime changes

test/unit/callbacks.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,3 +366,24 @@ QUnit.test( "jQuery.Callbacks() - disabled callback doesn't fire (gh-1790)", fun
366366
cb.fire();
367367
assert.ok( !fired, "Disabled callback function didn't fire" );
368368
} );
369+
370+
QUnit.test( "jQuery.Callbacks() - list with memory stays locked (gh-3469)", function( assert ) {
371+
372+
assert.expect( 3 );
373+
374+
var cb = jQuery.Callbacks( "memory" ),
375+
fired = 0,
376+
count1 = function() { fired += 1; },
377+
count2 = function() { fired += 10; };
378+
379+
cb.add( count1 );
380+
cb.fire();
381+
assert.equal( fired, 1, "Pre-lock() fire" );
382+
383+
cb.lock();
384+
cb.add( count2 );
385+
assert.equal( fired, 11, "Post-lock() add" );
386+
387+
cb.fire();
388+
assert.equal( fired, 11, "Post-lock() fire ignored" );
389+
} );

0 commit comments

Comments
 (0)