File size: 1,640 Bytes
6cd9596
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { Event } from './Face3';

/**
 * JavaScript events for custom objects
 *
 * # Example
 *     var Car = function () {
 *
 *         EventDispatcher.call( this );
 *         this.start = function () {
 *
 *             this.dispatchEvent( { type: 'start', message: 'vroom vroom!' } );
 *
 *         };
 *
 *     };
 *
 *     var car = new Car();
 *     car.addEventListener( 'start', function ( event ) {
 *
 *         alert( event.message );
 *
 *     } );
 *     car.start();
 *
 * @source src/core/EventDispatcher.js
 */
export class EventDispatcher {
  /**
   * Creates eventDispatcher object. It needs to be call with '.call' to add the functionality to an object.
   */
  constructor();

  /**
   * Adds a listener to an event type.
   * @param type The type of event to listen to.
   * @param listener The function that gets called when the event is fired.
   */
  addEventListener(type: string, listener: (event: Event) => void): void;

  /**
   * Checks if listener is added to an event type.
   * @param type The type of event to listen to.
   * @param listener The function that gets called when the event is fired.
   */
  hasEventListener(type: string, listener: (event: Event) => void): boolean;

  /**
   * Removes a listener from an event type.
   * @param type The type of the listener that gets removed.
   * @param listener The listener function that gets removed.
   */
  removeEventListener(type: string, listener: (event: Event) => void): void;

  /**
   * Fire an event type.
   * @param type The type of event that gets fired.
   */
  dispatchEvent(event: { type: string; [attachment: string]: any }): void;
}