event_utils.d.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. }
  22. /**
  23. * Simple event bus for an application. Listeners are attached using the `on`
  24. * and `off` methods. To raise an event, the `dispatch` method shall be used.
  25. */
  26. export class EventBus {
  27. _listeners: any;
  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. }
  54. /**
  55. * @typedef {Object} WaitOnEventOrTimeoutParameters
  56. * @property {Object} target - The event target, can for example be:
  57. * `window`, `document`, a DOM element, or an {EventBus} instance.
  58. * @property {string} name - The name of the event.
  59. * @property {number} delay - The delay, in milliseconds, after which the
  60. * timeout occurs (if the event wasn't already dispatched).
  61. */
  62. /**
  63. * Allows waiting for an event or a timeout, whichever occurs first.
  64. * Can be used to ensure that an action always occurs, even when an event
  65. * arrives late or not at all.
  66. *
  67. * @param {WaitOnEventOrTimeoutParameters}
  68. * @returns {Promise} A promise that is resolved with a {WaitOnType} value.
  69. */
  70. export function waitOnEventOrTimeout({ target, name, delay }: WaitOnEventOrTimeoutParameters): Promise<any>;
  71. export namespace WaitOnType {
  72. const EVENT: string;
  73. const TIMEOUT: string;
  74. }