UNPKG

5.18 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6/**
7 * Utility for sending and intercepting wrapped custom DOM events on the DOM or
8 * propagating them to the current controller.
9 *
10 * As with native events, the event fired by this event bus always propagate up
11 * the DOM tree until they reach the window.
12 *
13 * Note that the events fired by this event bus are wrapped in custom DOM
14 * events which always bear an obscure name set by the implementation of this
15 * interface, preventing custom event name collisions, and allowing observation
16 * and capture of all fired events. The actual event name is always consistent
17 * by the implementation.
18 *
19 * @interface
20 */
21class EventBus {
22 /**
23 * Fires a new custom event of the specified name, carrying the provided
24 * data.
25 *
26 * Note that this method does not prevent the event listeners to modify the
27 * data in any way. The order in which the event listeners will be executed
28 * is unspecified and should not be relied upon.
29 *
30 * Note that the default options are
31 * {@code { bubbles: true, cancelable: true }}, which is different from the
32 * default values used in the native custom events
33 * ({@code { bubbles: false, cancelable: false }}).
34 *
35 * @param {EventTarget} eventTarget The event target at which the event
36 * will be dispatched (e.g. element/document/window).
37 * @param {string} eventName The name of the event to fire.
38 * @param {*} data The data to pass to the event listeners.
39 * @param {{bubbles: boolean=, cancelable: boolean=}=} [options={}] The
40 * override of the default options passed to the constructor of the
41 * custom event fired by this event bus.
42 * The default options passed to the custom event constructor are
43 * {@code { bubbles: true, cancelable: true }}.
44 * @return {EventBus} This custom event bus.
45 * @throws {Error} Thrown if the provided event target cannot be used to
46 * fire the event.
47 * @see https://developer.mozilla.org/en-US/docs/Web/API/Event/Event
48 */
49 fire() {}
50
51 /**
52 * Registers the provided event listener to be executed when any custom
53 * event is fired using the same implementation of the event bus and passes
54 * through the specified event target.
55 *
56 * When the specified event is fired, the event listener will be executed
57 * with the event passed as the first argument.
58 *
59 * The order in which the event listeners will be executed is unspecified
60 * and should not be relied upon.
61 *
62 * @param {EventTarget} eventTarget The event target at which the listener
63 * should listen for all event bus events.
64 * @param {function(CustomEvent)} listener The event listener to
65 * register.
66 * @return {EventBus} This event bus.
67 */
68 listenAll() {}
69
70 /**
71 * Registers the provided event listener to be executed when the specific
72 * custom event is fired by the same implementation of the event bus and
73 * passes through the specified event target.
74 *
75 * When the specified event is fired, the event listener will be executed
76 * with the event passed as the first argument.
77 *
78 * The order in which the event listeners will be executed is unspecified
79 * and should not be relied upon.
80 *
81 * @param {EventTarget} eventTarget The event target at which the listener
82 * should listen for the specified event.
83 * @param {string} eventName The name of the event to listen for.
84 * @param {function(CustomEvent)} listener The event listener to
85 * register.
86 * @return {EventBus} This event bus.
87 */
88 listen() {}
89
90 /**
91 * Removes the provided event listener from the set of event listeners
92 * executed when the any custom event fired by the same implementation
93 * passes through the specified event target.
94 *
95 * The method has no effect if the listener is not registered at the
96 * specified event target.
97 *
98 * @param {EventTarget} eventTarget The event target at which the event
99 * listener listens for events.
100 * @param {function(CustomEvent)} listener The event listener to
101 * deregister.
102 * @return {EventBus} This event bus.
103 */
104 unlistenAll() {}
105
106 /**
107 * Removes the provided event listener from the set of event listeners
108 * executed when the specified custom event fired by the same
109 * implementation passes through the specified event target.
110 *
111 * The method has no effect if the listener is not registered for the
112 * specified event at the specified event target.
113 *
114 * @param {EventTarget} eventTarget The event target at which the listener
115 * is listening for the event.
116 * @param {string} eventName The name of the event listened for.
117 * @param {function(CustomEvent)} listener The event listener to
118 * deregister.
119 * @return {EventBus} This event bus.
120 */
121 unlisten() {}
122}
123exports.default = EventBus;
124
125typeof $IMA !== 'undefined' && $IMA !== null && $IMA.Loader && $IMA.Loader.register('ima/event/EventBus', [], function (_export, _context) {
126 'use strict';
127 return {
128 setters: [],
129 execute: function () {
130 _export('default', exports.default);
131 }
132 };
133});