From 70ae31fbc2c7b980346f59eb66479322013f95a0 Mon Sep 17 00:00:00 2001 From: Christopher Garrett Date: Tue, 6 Nov 2018 10:06:03 -0800 Subject: [PATCH] [BUGFIX] Ensures removeAllListeners doesn't break subsequent adds --- packages/@ember/-internals/meta/lib/meta.ts | 4 +++ .../-internals/meta/tests/listeners_test.js | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/packages/@ember/-internals/meta/lib/meta.ts b/packages/@ember/-internals/meta/lib/meta.ts index 2ea31b0db30..c4bf55046e7 100644 --- a/packages/@ember/-internals/meta/lib/meta.ts +++ b/packages/@ember/-internals/meta/lib/meta.ts @@ -619,6 +619,10 @@ export class Meta { } else { // update own listener listener.kind = kind; + + // TODO: Remove this when removing REMOVE_ALL, it won't be necessary + listener.target = target; + listener.method = method; } } } diff --git a/packages/@ember/-internals/meta/tests/listeners_test.js b/packages/@ember/-internals/meta/tests/listeners_test.js index bb1bdb0e2b0..8fe1eeeb36e 100644 --- a/packages/@ember/-internals/meta/tests/listeners_test.js +++ b/packages/@ember/-internals/meta/tests/listeners_test.js @@ -155,5 +155,31 @@ moduleFor( 'one reopen call after mutating parents and flattening out of order' ); } + + ['@test REMOVE_ALL does not interfere with future adds'](assert) { + expectDeprecation(() => { + let t = {}; + let m = meta({}); + + m.addToListeners('hello', t, 'm', 0); + let matching = m.matchingListeners('hello'); + + assert.equal(matching.length, 3); + assert.equal(matching[0], t); + + // Remove all listeners + m.removeAllListeners('hello'); + + matching = m.matchingListeners('hello'); + assert.equal(matching, undefined); + + m.addToListeners('hello', t, 'm', 0); + matching = m.matchingListeners('hello'); + + // listener was added back successfully + assert.equal(matching.length, 3); + assert.equal(matching[0], t); + }); + } } );