Interface EventApi

This API provides the details and functionality associated with publishing and subscribing to events.

Accessed from the window at window.sas.vi.event.

window.sas.vi.event.publish("eventName", payload);
interface EventApi {
    publish(eventName: string, payload?: any): void;
    subscribe(eventName: string, observer: ((payload: any) => void)): undefined | Subscription;
    unsubscribe(subscription: Subscription): void;
}

Methods

  • Parameters

    • eventName: string

      {string} Name of the event to publish.

    • Optionalpayload: any

      {any} Data passed to all subscribers.

    Returns void

    Publishes an event for subscribers to consume.

  • Parameters

    • eventName: string

      Name of the event to subscribe to.

    • observer: ((payload: any) => void)

      Invoked when the subscription is triggered by an event. Has access to the event's payload.

        • (payload): void
        • Parameters

          • payload: any

          Returns void

    Returns undefined | Subscription

    The subscription being made to the event.

    Subscribes to an event and registers a function to be called on any future published events. If the eventName does not exist, it is created.

  • Parameters

    • subscription: Subscription

      {Subscription} Subscription to stop.

    Returns void

    Unsubscribe from a given subscription and stop listening for events.