Class sap.ui.core.EventBusModule: sap/ui/core/EventBus

extends Object

Provides eventing capabilities for applications like firing events and attaching or detaching event handlers for events which are notified when events are fired.


Since: 1.8.0.
Constructor Summary
new sap.ui.core.EventBus()Creates an instance of EventBus.
Method Summary
sap.ui.core.EventBus.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.ui.core.EventBus with name sClassName and enriches it with the information contained in oClassInfo.
sap.ui.core.EventBus.getMetadata()Returns a metadata object for class sap.ui.core.EventBus.
destroy()Cleans up the internal structures and removes all event handlers.
publish(sChannelId?, sEventId, oData?)Fires an event using the specified settings and notifies all attached event handlers.
subscribe(sChannelId?, sEventId, fnFunction, oListener?)Attaches an event handler to the event with the given identifier on the given event channel.
subscribeOnce(sChannelId?, sEventId, fnFunction, oListener?)Attaches an event handler, called one time only, to the event with the given identifier on the given event channel.
unsubscribe(sChannelId?, sEventId, fnFunction, oListener?)Removes a previously subscribed event handler from the event with the given identifier on the given event channel.
Methods borrowed from class sap.ui.base.Object
Constructor Detail
new sap.ui.core.EventBus()
Creates an instance of EventBus.
Method Detail
sap.ui.core.EventBus.extend(sClassName, oClassInfo?, FNMetaImpl?): function
Creates a new subclass of class sap.ui.core.EventBus with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.base.Object.extend.

Parameters:
{string}sClassName Name of the class being created
{object}oClassInfo? Object literal with information about the class
{function}FNMetaImpl? Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
{function} Created class / constructor function
sap.ui.core.EventBus.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.ui.core.EventBus.
Returns:
{sap.ui.base.Metadata} Metadata object describing this class
destroy()
Cleans up the internal structures and removes all event handlers.

The object must not be used anymore after destroy was called.

See:
sap.ui.base.Object#destroy
publish(sChannelId?, sEventId, oData?)
Fires an event using the specified settings and notifies all attached event handlers.
Parameters:
{string}sChannelId? The channel of the event to fire. If not given, the default channel is used. The channel "sap.ui" is reserved by the UI5 framework. An application might listen to events on this channel but is not allowed to publish its own events there.
{string}sEventId The identifier of the event to fire
{object}oData? The parameters which should be carried by the event
subscribe(sChannelId?, sEventId, fnFunction, oListener?): sap.ui.core.EventBus
Attaches an event handler to the event with the given identifier on the given event channel.
Parameters:
{string}sChannelId? The channel of the event to subscribe to. If not given, the default channel is used. The channel "sap.ui" is reserved by the UI5 framework. An application might listen to events on this channel but is not allowed to publish its own events there.
{string}sEventId The identifier of the event to listen for
{function}fnFunction The handler function to call when the event occurs. This function will be called in the context of the oListener instance (if present) or on the event bus instance. The channel is provided as first argument of the handler, and the event identifier is provided as the second argument. The parameter map carried by the event is provided as the third argument (if present). Handlers must not change the content of this map.
{object}oListener? The object that wants to be notified when the event occurs (this context within the handler function). If it is not specified, the handler function is called in the context of the event bus.
Returns:
{sap.ui.core.EventBus} Returns this to allow method chaining
subscribeOnce(sChannelId?, sEventId, fnFunction, oListener?): sap.ui.core.EventBus
Attaches an event handler, called one time only, to the event with the given identifier on the given event channel.

When the event occurs, the handler function is called and the handler registration is automatically removed afterwards.

Parameters:
{string}sChannelId? The channel of the event to subscribe to. If not given, the default channel is used. The channel "sap.ui" is reserved by the UI5 framework. An application might listen to events on this channel but is not allowed to publish its own events there.
{string}sEventId The identifier of the event to listen for
{function}fnFunction The handler function to call when the event occurs. This function will be called in the context of the oListener instance (if present) or on the event bus instance. The channel is provided as first argument of the handler, and the event identifier is provided as the second argument. The parameter map carried by the event is provided as the third argument (if present). Handlers must not change the content of this map.
{object}oListener? The object that wants to be notified when the event occurs (this context within the handler function). If it is not specified, the handler function is called in the context of the event bus.
Since:
1.32.0
Returns:
{sap.ui.core.EventBus} Returns this to allow method chaining
unsubscribe(sChannelId?, sEventId, fnFunction, oListener?): sap.ui.core.EventBus
Removes a previously subscribed event handler from the event with the given identifier on the given event channel.

The passed parameters must match those used for registration with subscribe beforehand!

Parameters:
{string}sChannelId? The channel of the event to unsubscribe from. If not given, the default channel is used.
{string}sEventId The identifier of the event to unsubscribe from
{function}fnFunction The handler function to unsubscribe from the event
{object}oListener? The object that wanted to be notified when the event occurred
Returns:
{sap.ui.core.EventBus} Returns this to allow method chaining