Skip Navigation

EventBusService

Allows communication and coordination between components and Red Apps by using a centralized event bus, enabling loose coupling and scalability.

Keep in mind that such communication is asynchronous and one-directional. Events can be both sent by another Red App (or even the same) or triggered by SR360.

Usage

In order to be used, the EventBusService has to be imported:

import {EventBusService} from 'sabre-ngv-app/app/services/impl/EventBusService';

Once imported, it can be obtained in a standard way:

const service: EventBusService = getService(EventBusService);

Listening to the event

The service provides the following methods used to listen for an event:

listenToEventBus(eventName: string, listener: (...args: any[]) => void): void;

listenToEventBusOnce(eventName: string, listener: (...args: any[]) => void): void;

These methods take as a first parameter the name of event we want to handle, second parameter is an event handler/listener function.

Sending a custom event

The service provides the following method used to send a custom event:

triggerOnEventBus(eventName: string, ...any[]): void;

This method requires one mandatory parameter - event name, the second optional parameter is an object with the data we want to send with the event.

Additional information

See Events article for more information about SR360 defined events and creating custom events.