2022-09-05 23:57:11 +03:00
|
|
|
"use strict";
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
|
exports.EventPayload = void 0;
|
2022-11-30 23:44:23 +03:00
|
|
|
/**
|
2023-06-02 00:52:58 +03:00
|
|
|
* Events allow for applications to use the observer pattern, which
|
|
|
|
* allows subscribing and publishing events, outside the normal
|
|
|
|
* execution paths.
|
2022-11-30 23:44:23 +03:00
|
|
|
*
|
2022-12-03 05:27:06 +03:00
|
|
|
* @_section api/utils/events:Events [about-events]
|
2022-11-30 23:44:23 +03:00
|
|
|
*/
|
2022-09-05 23:57:11 +03:00
|
|
|
const properties_js_1 = require("./properties.js");
|
2023-01-28 09:53:29 +03:00
|
|
|
/**
|
|
|
|
* When an [[EventEmitterable]] triggers a [[Listener]], the
|
|
|
|
* callback always ahas one additional argument passed, which is
|
|
|
|
* an **EventPayload**.
|
|
|
|
*/
|
2022-09-05 23:57:11 +03:00
|
|
|
class EventPayload {
|
2023-01-28 09:53:29 +03:00
|
|
|
/**
|
|
|
|
* The event filter.
|
|
|
|
*/
|
2022-09-05 23:57:11 +03:00
|
|
|
filter;
|
2023-01-28 09:53:29 +03:00
|
|
|
/**
|
|
|
|
* The **EventEmitterable**.
|
|
|
|
*/
|
2022-09-05 23:57:11 +03:00
|
|
|
emitter;
|
|
|
|
#listener;
|
2023-01-28 09:53:29 +03:00
|
|
|
/**
|
|
|
|
* Create a new **EventPayload** for %%emitter%% with
|
|
|
|
* the %%listener%% and for %%filter%%.
|
|
|
|
*/
|
2022-09-05 23:57:11 +03:00
|
|
|
constructor(emitter, listener, filter) {
|
|
|
|
this.#listener = listener;
|
|
|
|
(0, properties_js_1.defineProperties)(this, { emitter, filter });
|
|
|
|
}
|
2023-01-28 09:53:29 +03:00
|
|
|
/**
|
|
|
|
* Unregister the triggered listener for future events.
|
|
|
|
*/
|
2022-09-05 23:57:11 +03:00
|
|
|
async removeListener() {
|
|
|
|
if (this.#listener == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
await this.emitter.off(this.filter, this.#listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
exports.EventPayload = EventPayload;
|
|
|
|
//# sourceMappingURL=events.js.map
|