This commit is contained in:
Daniel Imms
2022-10-01 08:55:01 -07:00
parent ed15a8e170
commit 03fcf60aaf
+13
View File
@@ -66,6 +66,19 @@ export class EventEmitter<T, U = void> implements IEventEmitter<T, U> {
}
}
/**
* Creates an object that implements both the {@link IEvent} and {@link IEmitter} interfaces. This
* allows more concise instantiation. The idea is to internally use the combined
* {@link IEventWithEmitter} interface and only expose {@link IEvent} externally.
*
* @example
* ```ts
* public readonly onFoo = initEvent<string>();
* // ...
* onFoo(e => handle(e));
* onFoo.fire('bar');
* ```
*/
export function initEvent<T, U = void>(): IEventWithEmitter<T, U> {
const emitter = new EventEmitter<T, U>();
const event = emitter.event;