# EventBroker Class

Defined in: `js/event/EventBroker.js:11`
Module: event
Parent Module: StructureJS

EventBroker is a simple publish and subscribe static class that you can use to fire and receive notifications. Loosely coupled event handling, the subscriber does not know the publisher. Both of them only need to know the event type.

## Index

Show: Inherited Protected Private Deprecated

### Properties

- _eventDispatcher static
- _waitForList static

### Methods

- _dispatchWaitFor static
- addEventListener static
- addEventListenerOnce static
- dispatchEvent static
- getEventListeners static
- hasEventListener static
- removeEventListener static
- removeWaitFor static
- waitFor static
- waitForOnce static

## Properties

### `_eventDispatcher` EventDispatcher private static

Defined in `js/event/EventBroker.js:256`

A reference to the EventDispatcher object.

### `_waitForList` Array, callback:Function, callbackScope:any, events:Array, once:boolean> private static

Defined in `js/event/EventBroker.js:265`

A list of wait for objects.

There are no properties that match your current filter settings. You can change your filter settings in the index section on this page. index

## Methods

### `_dispatchWaitFor` () private static

Defined in `js/event/EventBroker.js:199`

Helper method to dispatch events on the waitForObject objects.

### `addEventListener`
(

- `type`
- `callback`
- `scope`
- `[priority=0]`

)
public static

Defined in `js/event/EventBroker.js:27`

Registers an event listener object with an EventBroker object so that the listener receives notification of an event.

#### Parameters:

- `type` String

  The type of event.

- `callback` Function

  The listener function that processes the event. The callback function will receive a BaseEvent object or custom event that extends the BaseEvent class.

- `scope` Any

  The scope of the callback function.

- `[priority=0]` Int optional

  Influences the order in which the listeners are called. Listeners with lower priorities are called after ones with higher priorities.

#### Example:

    EventBroker.addEventListener('change', this._handlerMethod, this);
    // Example of using a constant event type.
    EventBroker.addEventListener(BaseEvent.CHANGE, this._handlerMethod, this);

    // The event passed to the method will always be a BaseEvent object.
    _handlerMethod(event) {
         console.log(event.data);
    }

### `addEventListenerOnce`
(

- `type`
- `callback`
- `scope`
- `[priority=0]`

)
public static

Defined in `js/event/EventBroker.js:51`

Registers an event listener object once with an EventDispatcher object so the listener will receive the notification of an event.

#### Parameters:

- `type` String

  The type of event.

- `callback` Function

  The listener function that processes the event. The callback function will receive a BaseEvent object or custom event that extends the BaseEvent class.

- `scope` Any

  The scope of the callback function.

- `[priority=0]` Int optional

  Influences the order in which the listeners are called. Listeners with lower priorities are called after ones with higher priorities.

#### Example:

    EventBroker.addEventListenerOnce('change', this._handlerMethod, this);
    // Example of using a constant event type.
    EventBroker.addEventListenerOnce(BaseEvent.CHANGE, this._handlerMethod, this);

    // The event passed to the method will always be a BaseEvent object.
    _handlerMethod(event) {
         console.log(event.data);
    }

### `dispatchEvent`
(

- `event`
- `[data=null]`
- `[scope=null]`

)
public static

Defined in `js/event/EventBroker.js:167`

Dispatches an event within the EventBroker object.

#### Parameters:

- `event` String | BaseEvent

  The Event object or event type string you want to dispatch.

- `[data=null]` Any optional

  The optional data you want to send with the event. Do not use this parameter if you are passing in a BaseEvent.

- `[scope=null]` Any optional

  You can optionally pass in the target of the object that dispatched the global event. Since EventBroker

#### Example:

     EventBroker.dispatchEvent('change');

     // Example: Sending data with the event.
     EventBroker.dispatchEvent('change', {some: 'data'});

     // Example: Sending a BaseEvent or custom event object.
     let event = new BaseEvent(BaseEvent.CHANGE);
     event.data = {some: 'data'};
     EventBroker.dispatchEvent(event);

### `getEventListeners` () String public static

Defined in `js/event/EventBroker.js:241`

Generates a string output of event listeners for a given object.

#### Returns:

String:

#### Example:

     EventBroker.getEventListeners();

     // [ClassName] is listen for 'BaseEvent.change' event.

### `hasEventListener`
(

- `type`
- `callback`
- `scope`

)
Boolean public static

Defined in `js/event/EventBroker.js:225`

Check if EventBroker has a specific event listener already added.

#### Parameters:

- `type` String

  The type of event.

- `callback` Function

  The listener method to call.

- `scope` Any

  The scope of the listener object.

#### Returns:

Boolean:

#### Example:

     EventBroker.hasEventListener(BaseEvent.CHANGE, this._handlerMethod, this);

### `removeEventListener`
(

- `type`
- `callback`
- `scope`

)
public static

Defined in `js/event/EventBroker.js:75`

Removes a specified listener from the EventBroker object.

#### Parameters:

- `type` String

  The type of event.

- `callback` Function

  The callback function to be removed.

- `scope` Any

  The scope of the callback function to be removed.

#### Example:

    EventBroker.removeEventListener('change', this._handlerMethod, this);

    EventBroker.removeEventListener(BaseEvent.CHANGE, this._handlerMethod, this);

### `removeWaitFor`
(

- `eventTypes`
- `callback`
- `scope`

)
public static

Defined in `js/event/EventBroker.js:146`

A way to listen for multiple events. Once all events all are triggered it will no longer

#### Parameters:

- `eventTypes` Array

  A list of event types you are waiting for.

- `callback` Function

  The callback function that will be triggered when all event types are

- `scope` Any

  The scope of the callback function.

#### Example:

    EventBroker.removeWaitFor(['someEvent', 'anotherEvent', CustomEvent.CHANGE], this._handlerMethod, this);

### `waitFor`
(

- `eventTypes`
- `callback`
- `scope`

)
public static

Defined in `js/event/EventBroker.js:92`

A way to listen for multiple events.

If only listening for one event use addEventListener.

#### Parameters:

- `eventTypes` Array

  A list of event types you are waiting for.

- `callback` Function

  The callback function that will be triggered when all event types are

- `scope` Any

  The scope of the callback function.

#### Example:

    EventBroker.waitFor(['someEvent', 'anotherEvent', CustomEvent.CHANGE], this._handlerMethod, this);

    _handlerMethod(events) {
         // An array of the event objects you waited for.
    }

### `waitForOnce`
(

- `eventTypes`
- `callback`
- `scope`

)
public static

Defined in `js/event/EventBroker.js:119`

A way to listen for multiple events. Once all events all are triggered this listener will be removed.

If only listening for one event use addEventListenerOnce.

#### Parameters:

- `eventTypes` Array

  A list of event types you are waiting for.

- `callback` Function

  The callback function that will be triggered when all event types are

- `scope` Any

  The scope of the callback function.

#### Example:

    EventBroker.waitForOnce(['someEvent', 'anotherEvent', CustomEvent.CHANGE], this._handlerMethod, this);

    _handlerMethod(events) {
         // An array of the event objects you waited for.
    }

There are no methods that match your current filter settings. You can change your filter settings in the index section on this page. index