@stoplight/lifecycle
Advanced tools
Comparing version 2.1.4 to 2.2.0
@@ -10,3 +10,3 @@ export interface IMinimalActivatable { | ||
protected _state: 'deactivated' | 'isActivating' | 'activated' | 'isDeactivating'; | ||
readonly state: "deactivated" | "isActivating" | "activated" | "isDeactivating"; | ||
get state(): "deactivated" | "isActivating" | "activated" | "isDeactivating"; | ||
activate(): Promise<void>; | ||
@@ -13,0 +13,0 @@ deactivate(): Promise<void>; |
@@ -5,3 +5,3 @@ import { IDisposable } from './types'; | ||
protected readonly disposables: IDisposable[]; | ||
readonly disposed: boolean; | ||
get disposed(): boolean; | ||
dispose(): void; | ||
@@ -8,0 +8,0 @@ push(disposable: IDisposable): IDisposable; |
import StrictEventEmitter from 'strict-event-emitter-types'; | ||
import { IDisposable } from '../disposable'; | ||
import { IEventEmitter, IEventEmitterInstance } from './types'; | ||
export interface IEventEmitter<E extends object> extends StrictEventEmitter<IEventEmitterInstance, E> { | ||
createEmitGroup(): { | ||
queueCount: number; | ||
emit: IEventEmitter<E>['emit']; | ||
flush: () => void; | ||
reset: () => void; | ||
}; | ||
} | ||
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> { | ||
private _emitter; | ||
on(type: unknown, listener: Function): IDisposable; | ||
emit(type: unknown, ...args: Array<unknown>): void; | ||
readonly hasListeners: boolean; | ||
emit(type: unknown, ...args: unknown[]): void; | ||
get hasListeners(): boolean; | ||
dispose(): void; | ||
createEmitGroup(): { | ||
queueCount: number; | ||
emit: EventEmitter<E>['emit']; | ||
flush: () => void; | ||
reset: () => void; | ||
}; | ||
} | ||
export declare function createEventEmitter<T extends object>(): new () => StrictEventEmitter<IEventEmitterInstance, T, T, "addListener" | "addEventListener" | "removeListener" | "removeEventListener" | "once", "on" | "emit">; |
@@ -33,2 +33,35 @@ "use strict"; | ||
} | ||
createEmitGroup() { | ||
const notifier = this; | ||
const eventQueue = []; | ||
let flushed = false; | ||
return { | ||
get queueCount() { | ||
return eventQueue.length; | ||
}, | ||
emit(event, ...args) { | ||
if (flushed) { | ||
notifier.emit(event, ...args); | ||
} | ||
else { | ||
eventQueue.push([event, args]); | ||
} | ||
}, | ||
flush() { | ||
for (const [event, args] of eventQueue) { | ||
try { | ||
notifier.emit(event, ...args); | ||
} | ||
catch (e) { | ||
} | ||
} | ||
this.reset(); | ||
flushed = true; | ||
}, | ||
reset() { | ||
eventQueue.length = 0; | ||
flushed = false; | ||
}, | ||
}; | ||
} | ||
} | ||
@@ -35,0 +68,0 @@ exports.EventEmitter = EventEmitter; |
export * from './emitter'; | ||
export * from './types'; |
{ | ||
"name": "@stoplight/lifecycle", | ||
"version": "2.1.4", | ||
"version": "2.2.0", | ||
"description": "Event and disposable helpers.", | ||
@@ -20,8 +20,7 @@ "keywords": [], | ||
}, | ||
"peerDependencies": {}, | ||
"dependencies": { | ||
"strict-event-emitter-types": "^2.0.0", | ||
"wolfy87-eventemitter": "5.2.6" | ||
"wolfy87-eventemitter": "~5.2.8" | ||
}, | ||
"typings": "index.d.ts" | ||
} |
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
29450
283
27
+ Addedwolfy87-eventemitter@5.2.9(transitive)
- Removedwolfy87-eventemitter@5.2.6(transitive)
Updatedwolfy87-eventemitter@~5.2.8