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

42 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

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