mirror of
https://git.tuxpa.in/a/code-server.git
synced 2024-12-26 20:25:25 +00:00
Add Callback type
Adds a reusable Callback type that is applied to emitter.ts for improved readability/simplicity.
This commit is contained in:
parent
8d03c22cb0
commit
a0ff2014c3
@ -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
1
src/common/types.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export type Callback<T, R = void> = (t: T) => R
|
Loading…
Reference in New Issue
Block a user