Class EventBusService

java.lang.Object
org.angular.ts.ng.EventBusService

@JsType(isNative=true, name="ng.EventBusService", namespace="<global>") public class EventBusService extends Object
Topic-based publish/subscribe service for decoupled application events.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Dispose the instance, removing all topics and listeners.
    double
    Get the number of subscribers for a topic.
    boolean
    Checks if instance has been disposed.
    boolean
    publish(String topic, Object... var_args)
    Publish a value to a topic asynchronously.
    void
    Reset the bus to its initial state without disposing it.
    void
    Replace the runtime delivery policy used by future publications.
    org.angular.ts.ng.EventBusService.Subscription
    subscribe(String topic, org.angular.ts.ng.EventBusService.EventBusListener fn)
    Subscribe a function to a topic.
    org.angular.ts.ng.EventBusService.Subscription
    subscribeOnce(String topic, org.angular.ts.ng.EventBusService.EventBusListener fn)
    Subscribe a function to a topic only once.
    boolean
    unsubscribe(String topic, org.angular.ts.ng.EventBusService.EventBusListener fn)
    Unsubscribe a specific function from a topic.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • EventBusService

      public EventBusService()
  • Method Details

    • dispose

      public void dispose()
      Dispose the instance, removing all topics and listeners.
    • getCount

      public double getCount(String topic)
      Get the number of subscribers for a topic. This is the public diagnostic surface for `$eventBus`. It reports active registered listeners only; topic listings, leak reports, and reactive diagnostics are intentionally not exposed.
      Parameters:
      topic - Topic name to inspect.
      Returns:
      Method result.
    • isDisposed

      public boolean isDisposed()
      Checks if instance has been disposed.
      Returns:
      Method result.
    • publish

      public boolean publish(String topic, Object... var_args)
      Publish a value to a topic asynchronously. Listeners are invoked in the order they were added until delivery finishes or `$exceptionHandler` terminates the publication. Delivery is scheduled with `queueMicrotask`. Scope-owned listeners are skipped if their scope is destroyed before the queued delivery runs.
      Parameters:
      topic - The topic to publish.
      var_args - Arguments to pass to listeners.
      Returns:
      Method result.
    • reset

      public void reset()
      Reset the bus to its initial state without disposing it. All topics and listeners are removed, and the instance can be reused.
    • setDeliveryPolicy

      public void setDeliveryPolicy(EventDeliveryPolicy policy)
      Replace the runtime delivery policy used by future publications. The default policy delivers every active listener. Configured policies can drop deliveries for specific topics, scopes, or application metadata.
      Parameters:
      policy - Value supplied for the policy parameter.
    • subscribe

      public org.angular.ts.ng.EventBusService.Subscription subscribe(String topic, org.angular.ts.ng.EventBusService.EventBusListener fn)
      Subscribe a function to a topic. The returned function removes only this listener registration. When `context` is provided, it becomes the listener `this` binding. When `context` is an AngularTS scope proxy, the scope also owns the listener lifecycle: destroying the scope removes the listener and prevents queued delivery from reaching the destroyed scope.
      Parameters:
      topic - The topic to subscribe to.
      fn - The callback function to invoke when published.
      Returns:
      Method result.
    • subscribeOnce

      public org.angular.ts.ng.EventBusService.Subscription subscribeOnce(String topic, org.angular.ts.ng.EventBusService.EventBusListener fn)
      Subscribe a function to a topic only once. Listener is removed before the first invocation. When `context` is provided, it becomes the listener `this` binding. When `context` is an AngularTS scope proxy, scope destruction before first delivery removes the one-time listener.
      Parameters:
      topic - The topic to subscribe to.
      fn - The callback function.
      Returns:
      Method result.
    • unsubscribe

      public boolean unsubscribe(String topic, org.angular.ts.ng.EventBusService.EventBusListener fn)
      Unsubscribe a specific function from a topic. Matches by function reference and optional context.
      Parameters:
      topic - The topic to unsubscribe from.
      fn - The listener function.
      Returns:
      Method result.