Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX lts] Remove all own listeners #18150

Merged
merged 1 commit into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions packages/@ember/-internals/meta/lib/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -594,14 +594,9 @@ export class Meta {
} else {
let listener = listeners[i];

// If the listener is our own function listener and we are trying to
// remove it, we want to splice it out entirely so we don't hold onto a
// reference.
if (
kind === ListenerKind.REMOVE &&
listener.kind !== ListenerKind.REMOVE &&
typeof method === 'function'
) {
// If the listener is our own listener and we are trying to remove it, we
// want to splice it out entirely so we don't hold onto a reference.
if (kind === ListenerKind.REMOVE && listener.kind !== ListenerKind.REMOVE) {
listeners.splice(i, 1);
} else {
assert(
Expand Down
28 changes: 28 additions & 0 deletions packages/@ember/-internals/meta/tests/listeners_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,33 @@ moduleFor(
'one reopen call after mutating parents and flattening out of order'
);
}

'@test removed listeners are removed from the underlying structure GH#1112213'(assert) {
// this is using private API to confirm the underlying data structure is properly maintained
// and should be changed to match the data structure as needed

class Class1 {}
let class1Meta = meta(Class1.prototype);
class1Meta.addToListeners('hello', null, 'm', 0);

let instance1 = new Class1();
let m1 = meta(instance1);

function listenerFunc() {}

m1.removeFromListeners('hello', null, 'm', 0);

m1.addToListeners('stringListener', null, 'm', 0);
m1.addToListeners('functionListener', null, listenerFunc, 0);

m1.removeFromListeners('functionListener', null, listenerFunc, 0);
m1.removeFromListeners('stringListener', null, 'm', 0);

assert.equal(
m1.flattenedListeners().length,
1,
'instance listeners correctly removed, inherited listeners remain'
);
}
}
);