ste-promise-events
Version:
Add the power of Events to your projects. They are styled after .Net using a sender and arguments. Handlers can be promises.
40 lines (39 loc) • 1.23 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NonUniformPromiseEventList = void 0;
const PromiseEventDispatcher_1 = require("./PromiseEventDispatcher");
/**
* Similar to EventList, but instead of TArgs, a map of event names ang argument types is provided with TArgsMap.
*/
class NonUniformPromiseEventList {
constructor() {
this._events = {};
}
/**
* Gets the dispatcher associated with the name.
* @param name The name of the event.
*/
get(name) {
if (this._events[name]) {
// @TODO avoid typecasting. Not sure why TS thinks this._events[name] could still be undefined.
return this._events[name];
}
const event = this.createDispatcher();
this._events[name] = event;
return event;
}
/**
* Removes the dispatcher associated with the name.
* @param name The name of the event.
*/
remove(name) {
delete this._events[name];
}
/**
* Creates a new dispatcher instance.
*/
createDispatcher() {
return new PromiseEventDispatcher_1.PromiseEventDispatcher();
}
}
exports.NonUniformPromiseEventList = NonUniformPromiseEventList;