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

Fix evented.listens to return false when no listener exists #10281

Merged
merged 1 commit into from
Jan 12, 2021
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: 2 additions & 2 deletions src/util/evented.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,14 @@ export class Evented {
}

/**
* Returns a true if this instance of Evented or any forwardeed instances of Evented have a listener for the specified type.
* Returns true if this instance of Evented or any forwarded instances of Evented have a listener for the specified type.
*
* @param {string} type The event type
* @returns {boolean} `true` if there is at least one registered listener for specified event type, `false` otherwise
* @private
*/
listens(type: string) {
return (
return !!(
(this._listeners && this._listeners[type] && this._listeners[type].length > 0) ||
(this._oneTimeListeners && this._oneTimeListeners[type] && this._oneTimeListeners[type].length > 0) ||
(this._eventedParent && this._eventedParent.listens(type))
Expand Down
2 changes: 1 addition & 1 deletion test/unit/util/evented.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ test('Evented', (t) => {
const evented = new Evented();
evented.on('a', () => {});
t.ok(evented.listens('a'));
t.notOk(evented.listens('b'));
t.equals(evented.listens('b'), false);
t.end();
});

Expand Down