Class PubSub

Class that enables implementation of publish/subscribe design pattern.

Hierarchy

  • PubSub

Constructors

  • Returns PubSub

Properties

#lastSubscriptionId: number

Unique ID to control the associated subscription callback handlers.

#subscriptions: Map<string, CallbackMap>

Map containing all the active event subscriptions and their associated callback handlers.

Methods

  • Checks if the provided callback function is valid and throws PubSubError if it is invalid.

    Throws

    PubSubError

    Parameters

    • callback: Handler

      Function to be checked

    Returns void

  • Checks if the provided event name is valid and throws PubSubError if it is invalid.

    Throws

    PubSubError

    Parameters

    • eventName: string

      Event name to be checked

    Returns void

  • Handles unsubscription for the provided event name and callback function.

    Parameters

    • eventName: string

      Event name for the registered callback

    • callback: Handler

      Function to have its subscription removed

    Returns void

  • Sealed

    Trigger all registered subscription callbacks for a specific event name.

    Parameters

    • eventName: string

      Event name to trigger subscriptions from

    • Rest ...payload: unknown[]

      Payload to be passed to the callback function

    Returns void

  • Sealed

    Adds a subscription callback for the provided event name.

    Parameters

    • eventName: string

      Event name that will trigger the callback

    • callback: Handler

      Function to be executed when event is published

    Returns void

  • Sealed

    Removes subscription callback(s) for the provided event name.

    If callback not provided, all the callbacks for the provided event name will be removed.

    Parameters

    • eventName: string

      Event name for the registered callback

    Returns void

  • Parameters

    • eventName: string
    • callback: Handler

    Returns void

  • Sealed

    Clears all subscriptions for this instance.

    Returns void

Generated using TypeDoc