Archived
1
0

Make event listeners never undefined, remove unused func

This commit is contained in:
Asher 2019-02-06 10:16:43 -06:00
parent e770920be0
commit 94f977845a
No known key found for this signature in database
GPG Key ID: 7BB4BA9C783D2BBC

View File

@ -5,14 +5,10 @@ export interface Event<T> {
} }
/** /**
* Emitter typecasts for a single event type * Emitter typecasts for a single event type.
*/ */
export class Emitter<T> { export class Emitter<T> {
private listeners: Array<(e: T) => void> | undefined; private listeners = <Array<(e: T) => void>>[];
public constructor() {
this.listeners = [];
}
public get event(): Event<T> { public get event(): Event<T> {
return (cb: (e: T) => void): IDisposable => { return (cb: (e: T) => void): IDisposable => {
@ -34,7 +30,7 @@ export class Emitter<T> {
} }
/** /**
* Emit a value * Emit an event with a value.
*/ */
public emit(value: T): void { public emit(value: T): void {
if (this.listeners) { if (this.listeners) {
@ -43,16 +39,9 @@ export class Emitter<T> {
} }
/** /**
* Disposes the event emitter * Dispose the current events.
*/ */
public dispose(): void { public dispose(): void {
this.listeners = undefined; this.listeners = [];
}
/**
* Whether the event has listeners.
*/
public get hasListeners(): boolean {
return !!this.listeners && this.listeners.length > 0;
} }
} }