From a0ff2014c36c521200fc57247d38987b63223d6a Mon Sep 17 00:00:00 2001 From: G r e y Date: Sat, 8 Aug 2020 22:18:49 -0500 Subject: [PATCH] Add Callback type Adds a reusable Callback type that is applied to emitter.ts for improved readability/simplicity. --- src/common/emitter.ts | 8 +++++--- src/common/types.ts | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) create mode 100644 src/common/types.ts diff --git a/src/common/emitter.ts b/src/common/emitter.ts index e30e0543..7a1ebf66 100644 --- a/src/common/emitter.ts +++ b/src/common/emitter.ts @@ -1,19 +1,21 @@ +import { Callback } from "./types" + export interface Disposable { dispose(): void } export interface Event { - (listener: (value: T) => void): Disposable + (listener: Callback): Disposable } /** * Emitter typecasts for a single event type. */ export class Emitter { - private listeners: Array<(value: T) => void> = [] + private listeners: Array> = [] public get event(): Event { - return (cb: (value: T) => void): Disposable => { + return (cb: Callback): Disposable => { this.listeners.push(cb) return { diff --git a/src/common/types.ts b/src/common/types.ts new file mode 100644 index 00000000..a8a0e4c1 --- /dev/null +++ b/src/common/types.ts @@ -0,0 +1 @@ +export type Callback = (t: T) => R