All files / ima/event Dispatcher.js

100% Statements 2/2
0% Branches 0/3
25% Functions 1/4
100% Lines 2/2
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81    6x                                                                                                                                                         6x  
import ns from '../namespace';
 
ns.namespace('ima.event');
 
/**
 * A Dispatcher is a utility that manager event listeners registered for events
 * and allows distributing (firing) events to the listeners registered for the
 * given event.
 *
 * The dispatcher provides a single-node event bus and is usually used to
 * propagate events from controllers to UI components when modifying/passing
 * the state is impractical for any reason.
 *
 * @interface
 */
export default class Dispatcher {
  /**
	 * Deregisters all event listeners currently registered with this
	 * dispatcher.
	 *
	 * @return {Dispatcher} This dispatcher.
	 */
  clear() {}
 
  /**
	 * Registers the provided event listener to be executed when the specified
	 * event is fired on this dispatcher.
	 *
	 * When the specified event is fired, the event listener will be executed
	 * with the data passed with the event as the first argument.
	 *
	 * The order in which the event listeners will be executed is unspecified
	 * and should not be relied upon. Registering the same listener for the
	 * same event and with the same scope multiple times has no effect.
	 *
	 * @param {string} event The name of the event to listen for.
	 * @param {function(*)} listener The event listener to register.
	 * @param {?Object=} scope The object to which the {@code this} keyword
	 *        will be bound in the event listener.
	 * @return {Dispatcher} This dispatcher.
	 */
  listen(event, listener, scope = null) {}
 
  /**
	 * Deregisters the provided event listener, so it will no longer be
	 * executed with the specified scope when the specified event is fired.
	 *
	 * @param {string} event The name of the event for which the listener
	 *        should be deregistered.
	 * @param {function(*)} listener The event listener to deregister.
	 * @param {?Object=} scope The object to which the {@code this} keyword
	 *        would be bound in the event listener.
	 * @return {Dispatcher} This dispatcher.
	 */
  unlisten(event, listener, scope = null) {}
 
  /**
	 * Fires a new event of the specified name, carrying the provided data.
	 *
	 * The method will synchronously execute all event listeners registered for
	 * the specified event, passing the provided data to them as the first
	 * argument.
	 *
	 * Note that this method does not prevent the event listeners to modify the
	 * data in any way. The order in which the event listeners will be executed
	 * is unspecified and should not be relied upon.
	 *
	 * @param {string} event The name of the event to fire.
	 * @param {Object<string, *>} data The data to pass to the event listeners.
	 * @param {boolean=} [imaInternalEvent=false] The flag signalling whether
	 *        this is an internal IMA event. The fired event is treated as a
	 *        custom application event if this flag is not set.
	 *        The flag is used only for debugging and has no effect on the
	 *        propagation of the event.
	 * @return {Dispatcher} This dispatcher.
	 */
  fire(event, data, imaInternalEvent = false) {}
}
 
ns.ima.event.Dispatcher = Dispatcher;