Add function to check if there is a listener for an event.

This commit is contained in:
kovacsv 2022-07-02 22:47:55 +02:00
parent 2a80468276
commit 71958671bc
2 changed files with 8 additions and 0 deletions

View File

@ -14,6 +14,11 @@ export class EventNotifier
listeners.push (listener);
}
HasEventListener (name)
{
return this.eventListeners.has (name);
}
NotifyEventListeners (name, ...args)
{
if (!this.eventListeners.has (name)) {

View File

@ -62,6 +62,9 @@ describe ('Core', function () {
});
en.NotifyEventListeners ('first_event', 5);
en.NotifyEventListeners ('second_event', 10, 15);
assert.ok (en.HasEventListener ('first_event'));
assert.ok (en.HasEventListener ('second_event'));
assert.ok (!en.HasEventListener ('third_event'));
assert.strictEqual (sumValues, 90);
});
});