40 lines
996 B
JavaScript
40 lines
996 B
JavaScript
/**
|
|
* Explain events...
|
|
*
|
|
* @_section api/utils/events:Events [about-events]
|
|
*/
|
|
import { defineProperties } from "./properties.js";
|
|
/**
|
|
* When an [[EventEmitterable]] triggers a [[Listener]], the
|
|
* callback always ahas one additional argument passed, which is
|
|
* an **EventPayload**.
|
|
*/
|
|
export class EventPayload {
|
|
/**
|
|
* The event filter.
|
|
*/
|
|
filter;
|
|
/**
|
|
* The **EventEmitterable**.
|
|
*/
|
|
emitter;
|
|
#listener;
|
|
/**
|
|
* Create a new **EventPayload** for %%emitter%% with
|
|
* the %%listener%% and for %%filter%%.
|
|
*/
|
|
constructor(emitter, listener, filter) {
|
|
this.#listener = listener;
|
|
defineProperties(this, { emitter, filter });
|
|
}
|
|
/**
|
|
* Unregister the triggered listener for future events.
|
|
*/
|
|
async removeListener() {
|
|
if (this.#listener == null) {
|
|
return;
|
|
}
|
|
await this.emitter.off(this.filter, this.#listener);
|
|
}
|
|
}
|
|
//# sourceMappingURL=events.js.map
|