From c9b5f83c7a377f4b664f07b10971e59a865c7ce5 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 15 Jun 2021 04:23:28 -0500 Subject: [PATCH] chore: add types for sb-event-kit --- lib/types/sb-event-kit.d.ts | 85 +++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 lib/types/sb-event-kit.d.ts diff --git a/lib/types/sb-event-kit.d.ts b/lib/types/sb-event-kit.d.ts new file mode 100644 index 0000000..37db58c --- /dev/null +++ b/lib/types/sb-event-kit.d.ts @@ -0,0 +1,85 @@ +// Type definitions for sb-event-kit 3.0.0 +// Project: https://github.com/steelbrain/event-kit +// Definitions by: Amin Yahyaabadi +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 4 + +declare module "sb-event-kit" { + /** A handle to a resource that can be disposed. */ + export class Disposable { + /** A callback which will be called within dispose(). */ + callback?: () => void + + disposed: boolean + + /** Construct a Disposable. */ + constructor(disposableAction?: () => void) + + /** Perform the disposal action, indicating that the resource associated with this disposable is no longer needed. */ + dispose(): void + } + + /** + * An object that aggregates multiple Disposable instances together into a single disposable, so they can all be + * disposed as a group. + */ + export class CompositeDisposable { + disposed: boolean + + /** Construct an instance, optionally with one or more disposables. */ + constructor(...disposables: Array) + + /** + * Dispose all disposables added to this composite disposable. If this object has already been disposed, this method + * has no effect. + */ + dispose(): void + + // Managing Disposables + /** + * Add disposables to be disposed when the composite is disposed. If this object has already been disposed, this + * method has no effect. + */ + add(...disposables: Array): void + + /** Remove disposables */ + delete(disposable: Array): void + + /** Clear all disposables. They will not be disposed by the next call to dispose. */ + clear(): void + } + + /** + * Utility class to be used when implementing event-based APIs that allows for handlers registered via ::on to be + * invoked with calls to ::emit. + */ + // tslint:disable-next-line:no-any + export class Emitter { + disposed: boolean + handlers: Object + + /** Construct an emitter. */ + constructor() + + /** Clear out any existing subscribers. */ + clear(): void + + /** Unsubscribe all handlers. */ + dispose(): boolean + + // Event Subscription + /** Registers a handler to be invoked whenever the given event is emitted. */ + on(eventName: T, handler: (value?: OptionalEmissions[T]) => void): Disposable + /** Registers a handler to be invoked whenever the given event is emitted. */ + on(eventName: T, handler: (value: RequiredEmissions[T]) => void): Disposable + + off(eventName: T, handler: (value?: OptionalEmissions[T]) => void): void + off(eventName: T, handler: (value: RequiredEmissions[T]) => void): void + + // Event Emission + /** Invoke the handlers registered via ::on for the given event name. */ + emit(eventName: T, ...value: Array): Promise> + /** Invoke the handlers registered via ::on for the given event name. */ + emit(eventName: T, ...value: Array): Promise> + } +}