AngularTS
    Preparing search index...

    Class PubSub

    Index

    Constructors

    • Create a publish/subscribe event bus.

      Applications usually receive the singleton instance by injecting $eventBus instead of constructing this class directly.

      Parameters

      Returns PubSub

    Methods

    • Dispose the instance, removing all topics and listeners.

      Returns void

    • Get the number of subscribers for a topic.

      Parameters

      • topic: string

        Topic name to inspect.

      Returns number

      The number of currently registered listeners.

    • Checks if instance has been disposed.

      Returns boolean

      True if disposed.

    • Publish a value to a topic asynchronously.

      All listeners are invoked in the order they were added. Delivery is scheduled with queueMicrotask.

      Parameters

      • topic: string

        The topic to publish.

      • ...args: unknown[]

        Arguments to pass to listeners.

      Returns boolean

      True if any listeners exist for this topic.

    • Reset the bus to its initial state without disposing it.

      All topics and listeners are removed, and the instance can be reused.

      Returns void

    • Subscribe a function to a topic.

      The returned function removes only this listener registration.

      Parameters

      • topic: string

        The topic to subscribe to.

      • fn: PubSubListener

        The callback function to invoke when published.

      • Optionalcontext: unknown

        Optional this context for the callback.

      Returns () => boolean

      A function that unsubscribes this listener.

    • Subscribe a function to a topic only once.

      Listener is removed before the first invocation.

      Parameters

      • topic: string

        The topic to subscribe to.

      • fn: PubSubListener

        The callback function.

      • Optionalcontext: unknown

        Optional this context for the callback.

      Returns () => boolean

      A function that unsubscribes this listener.

    • Unsubscribe a specific function from a topic. Matches by function reference and optional context.

      Parameters

      • topic: string

        The topic to unsubscribe from.

      • fn: PubSubListener

        The listener function.

      • Optionalcontext: unknown

        Optional this context.

      Returns boolean

      True if the listener was found and removed.