Use hash private

This commit is contained in:
2026-08-07 01:43:49 +00:00
parent c7f8637ea0
commit 3664464903
+8 -8
View File
@@ -35,7 +35,7 @@ export class EventEmitter<T extends EventMap> {
* The listeners map.
* @private
*/
private listeners: Map<keyof T, Set<ListenerEntry<T[keyof T]>>> = new Map();
#listeners: Map<keyof T, Set<ListenerEntry<T[keyof T]>>> = new Map();
/**
* Add a listener for an event.
@@ -49,8 +49,8 @@ export class EventEmitter<T extends EventMap> {
const wrappedListener = debounceMilliseconds && debounceMilliseconds > 0 ? this.debounce(listener, debounceMilliseconds) : listener;
// If the listeners map does not have the event type, create a new set.
if (!this.listeners.has(type)) {
this.listeners.set(type, new Set());
if (!this.#listeners.has(type)) {
this.#listeners.set(type, new Set());
}
// Create a listener entry.
@@ -85,8 +85,8 @@ export class EventEmitter<T extends EventMap> {
debounceMilliseconds && debounceMilliseconds > 0 ? this.debounce(wrappedListener, debounceMilliseconds) : wrappedListener;
// If the listeners map does not have the event type, create a new set.
if (!this.listeners.has(type)) {
this.listeners.set(type, new Set());
if (!this.#listeners.has(type)) {
this.#listeners.set(type, new Set());
}
// Create a listener entry.
@@ -111,7 +111,7 @@ export class EventEmitter<T extends EventMap> {
*/
off<K extends keyof T>(type: K, listener: Listener<T[K]>): void {
// Get the listeners for the event type.
const listeners = this.listeners.get(type);
const listeners = this.#listeners.get(type);
if (!listeners) return;
// Find the listener entry.
@@ -131,7 +131,7 @@ export class EventEmitter<T extends EventMap> {
*/
emit<K extends keyof T>(type: K, payload: T[K]): boolean {
// Get the listeners for the event type.
const listeners = this.listeners.get(type);
const listeners = this.#listeners.get(type);
if (!listeners) return false;
// Freeze the payload to make it readonly.
@@ -150,7 +150,7 @@ export class EventEmitter<T extends EventMap> {
* Remove all listeners.
*/
removeAllListeners(): void {
this.listeners.clear();
this.#listeners.clear();
}
/**