Use private fields in a few more viewer classes

These properties were always intended to be *private*, so let's use modern JS features to actually enforce that.
This commit is contained in:
Jonas Jenwald 2022-11-04 15:29:45 +01:00
parent eda51d1dcc
commit e7a6e7393a
3 changed files with 12 additions and 18 deletions

View file

@ -75,9 +75,7 @@ function waitOnEventOrTimeout({ target, name, delay = 0 }) {
* and `off` methods. To raise an event, the `dispatch` method shall be used.
*/
class EventBus {
constructor() {
this._listeners = Object.create(null);
}
#listeners = Object.create(null);
/**
* @param {string} eventName
@ -108,7 +106,7 @@ class EventBus {
* @param {Object} data
*/
dispatch(eventName, data) {
const eventListeners = this._listeners[eventName];
const eventListeners = this.#listeners[eventName];
if (!eventListeners || eventListeners.length === 0) {
return;
}
@ -139,7 +137,7 @@ class EventBus {
* @ignore
*/
_on(eventName, listener, options = null) {
const eventListeners = (this._listeners[eventName] ||= []);
const eventListeners = (this.#listeners[eventName] ||= []);
eventListeners.push({
listener,
external: options?.external === true,
@ -151,7 +149,7 @@ class EventBus {
* @ignore
*/
_off(eventName, listener, options = null) {
const eventListeners = this._listeners[eventName];
const eventListeners = this.#listeners[eventName];
if (!eventListeners) {
return;
}