ste-promise-simple-events
Version:
Add the power of Simple Events to your projects. Every event has an argument with its data. Every handler can be a promise.
40 lines (39 loc) • 1.28 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NonUniformPromiseSimpleEventList = void 0;
const PromiseSimpleEventDispatcher_1 = require("./PromiseSimpleEventDispatcher");
/**
* Similar to EventList, but instead of TArgs, a map of event names ang argument types is provided with TArgsMap.
*/
class NonUniformPromiseSimpleEventList {
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 PromiseSimpleEventDispatcher_1.PromiseSimpleEventDispatcher();
}
}
exports.NonUniformPromiseSimpleEventList = NonUniformPromiseSimpleEventList;