Archived
1
0

Merge pull request #1955 from cdr/callback-type

Add Callback type
This commit is contained in:
G r e y 2020-08-11 00:41:28 -04:00 committed by GitHub
commit 2fad8a2a58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 3 deletions

View File

@ -1,19 +1,21 @@
import { Callback } from "./types"
export interface Disposable { export interface Disposable {
dispose(): void dispose(): void
} }
export interface Event<T> { export interface Event<T> {
(listener: (value: T) => void): Disposable (listener: Callback<T>): Disposable
} }
/** /**
* 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<(value: T) => void> = [] private listeners: Array<Callback<T>> = []
public get event(): Event<T> { public get event(): Event<T> {
return (cb: (value: T) => void): Disposable => { return (cb: Callback<T>): Disposable => {
this.listeners.push(cb) this.listeners.push(cb)
return { return {

1
src/common/types.ts Normal file
View File

@ -0,0 +1 @@
export type Callback<T, R = void> = (t: T) => R