@websolutespa/payload-plugin-bowl
Version:
Bowl PayloadCms plugin of the BOM Repository
38 lines (37 loc) • 985 B
JavaScript
export class EventEmitter {
handlerCount = 0;
handlers = [];
options;
constructor(options){
this.options = options;
}
get numberOfHandlers() {
return this.handlers.filter((h)=>!!h).length;
}
async emit(payload) {
const promises = [];
this.options?.logger?.('emit', payload);
for (const handler of this.handlers){
if (handler) {
const res = handler(payload);
if (typeof res?.then === 'function') {
promises.push(res);
}
}
}
await Promise.all(promises);
}
on(handler) {
this.options?.logger?.('on');
this.handlers.push(handler);
return this.handlerCount++;
}
off(handlerId) {
this.delete(handlerId);
}
delete(handlerId) {
this.options?.logger?.('off');
this.handlers[handlerId] = null;
}
}
//# sourceMappingURL=EventEmitter.js.map