@stoplight/lifecycle
Advanced tools
Comparing version 2.3.0 to 2.3.1
@@ -1,21 +0,21 @@ | ||
import StrictEventEmitter from 'strict-event-emitter-types'; | ||
import { IDisposable } from '../disposable'; | ||
export interface IEmitGroup<E extends object> { | ||
export declare type EventMap = { | ||
[key: string]: (...args: any[]) => void; | ||
}; | ||
export interface IEmitGroup<E extends EventMap> { | ||
queueCount: number; | ||
emit: EventEmitter<E>['emit']; | ||
emit<P extends keyof E>(type: P, ...args: Parameters<E[P]>): void; | ||
flush: () => void; | ||
reset: () => void; | ||
} | ||
export interface IEventEmitter<E extends object> extends StrictEventEmitter<IEventEmitterInstance, E> { | ||
export interface IEventEmitter<E extends EventMap> extends IDisposable { | ||
on<P extends keyof E>(type: P, listener: E[P]): IDisposable; | ||
emit<P extends keyof E>(type: P, ...args: Parameters<E[P]>): void; | ||
hasListeners: boolean; | ||
createEmitGroup(): IEmitGroup<E>; | ||
} | ||
export interface IEventEmitterInstance extends IDisposable { | ||
on(type: number | string, listener: any): IDisposable; | ||
emit<A extends unknown[] = unknown[]>(type: number | string, ...args: A): void; | ||
hasListeners: boolean; | ||
} | ||
export declare class EventEmitter<E extends object> implements IEventEmitter<E> { | ||
export declare class EventEmitter<E extends EventMap> implements IEventEmitter<E> { | ||
private _emitter; | ||
on(type: unknown, listener: Function): IDisposable; | ||
emit(type: unknown, ...args: unknown[]): void; | ||
on<P extends keyof E>(type: P, listener: E[P]): IDisposable; | ||
emit<P extends keyof E>(type: P, ...args: Parameters<E[P]>): void; | ||
get hasListeners(): boolean; | ||
@@ -25,2 +25,1 @@ dispose(): void; | ||
} | ||
export declare function createEventEmitter<T extends object>(): new () => StrictEventEmitter<IEventEmitterInstance, T, T, "addListener" | "addEventListener" | "removeListener" | "removeEventListener" | "once", "emit" | "on">; |
@@ -10,5 +10,13 @@ "use strict"; | ||
on(type, listener) { | ||
this._emitter.on(String(type), listener); | ||
const wrappedListener = (...args) => { | ||
try { | ||
listener(...args); | ||
} | ||
catch (ex) { | ||
console.error(ex); | ||
} | ||
}; | ||
this._emitter.on(String(type), wrappedListener); | ||
return disposable_1.createDisposable(() => { | ||
this._emitter.off(String(type), listener); | ||
this._emitter.off(String(type), wrappedListener); | ||
}); | ||
@@ -69,7 +77,2 @@ } | ||
exports.EventEmitter = EventEmitter; | ||
function createEventEmitter() { | ||
const TypedEmitter = EventEmitter; | ||
return TypedEmitter; | ||
} | ||
exports.createEventEmitter = createEventEmitter; | ||
//# sourceMappingURL=emitter.js.map |
{ | ||
"name": "@stoplight/lifecycle", | ||
"version": "2.3.0", | ||
"version": "2.3.1", | ||
"description": "Event and disposable helpers.", | ||
@@ -21,3 +21,2 @@ "keywords": [], | ||
"dependencies": { | ||
"strict-event-emitter-types": "^2.0.0", | ||
"wolfy87-eventemitter": "~5.2.8" | ||
@@ -24,0 +23,0 @@ }, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1
414
36642
- Removedstrict-event-emitter-types@^2.0.0
- Removedstrict-event-emitter-types@2.0.0(transitive)