event_utils.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. export type WaitOnEventOrTimeoutParameters = {
  2. /**
  3. * - The event target, can for example be:
  4. * `window`, `document`, a DOM element, or an {EventBus} instance.
  5. */
  6. target: Object;
  7. /**
  8. * - The name of the event.
  9. */
  10. name: string;
  11. /**
  12. * - The delay, in milliseconds, after which the
  13. * timeout occurs (if the event wasn't already dispatched).
  14. */
  15. delay: number;
  16. };
  17. /**
  18. * NOTE: Only used to support various PDF viewer tests in `mozilla-central`.
  19. */
  20. export class AutomationEventBus extends EventBus {
  21. dispatch(eventName: any, data: any): void;
  22. }
  23. /**
  24. * Simple event bus for an application. Listeners are attached using the `on`
  25. * and `off` methods. To raise an event, the `dispatch` method shall be used.
  26. */
  27. export class EventBus {
  28. /**
  29. * @param {string} eventName
  30. * @param {function} listener
  31. * @param {Object} [options]
  32. */
  33. on(eventName: string, listener: Function, options?: Object | undefined): void;
  34. /**
  35. * @param {string} eventName
  36. * @param {function} listener
  37. * @param {Object} [options]
  38. */
  39. off(eventName: string, listener: Function, options?: Object | undefined): void;
  40. /**
  41. * @param {string} eventName
  42. * @param {Object} data
  43. */
  44. dispatch(eventName: string, data: Object): void;
  45. /**
  46. * @ignore
  47. */
  48. _on(eventName: any, listener: any, options?: null): void;
  49. /**
  50. * @ignore
  51. */
  52. _off(eventName: any, listener: any, options?: null): void;
  53. #private;
  54. }
  55. /**
  56. * @typedef {Object} WaitOnEventOrTimeoutParameters
  57. * @property {Object} target - The event target, can for example be:
  58. * `window`, `document`, a DOM element, or an {EventBus} instance.
  59. * @property {string} name - The name of the event.
  60. * @property {number} delay - The delay, in milliseconds, after which the
  61. * timeout occurs (if the event wasn't already dispatched).
  62. */
  63. /**
  64. * Allows waiting for an event or a timeout, whichever occurs first.
  65. * Can be used to ensure that an action always occurs, even when an event
  66. * arrives late or not at all.
  67. *
  68. * @param {WaitOnEventOrTimeoutParameters}
  69. * @returns {Promise} A promise that is resolved with a {WaitOnType} value.
  70. */
  71. export function waitOnEventOrTimeout({ target, name, delay }: WaitOnEventOrTimeoutParameters): Promise<any>;
  72. export namespace WaitOnType {
  73. const EVENT: string;
  74. const TIMEOUT: string;
  75. }