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

42 lines
1.1 KiB
JavaScript
Raw Normal View History

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
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