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] Ensures removeAllListeners doesn't break subsequent adds #17184

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
4 changes: 4 additions & 0 deletions packages/@ember/-internals/meta/lib/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions packages/@ember/-internals/meta/tests/listeners_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}
}
);