ethers.js/lib.esm/utils/events.js

40 lines
996 B
JavaScript
Raw Normal View History

2022-11-30 23:44:23 +03:00
/**
* Explain events...
*
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
import { defineProperties } from "./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
export 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;
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);
}
}
//# sourceMappingURL=events.js.map