Package org.angular.ts.ng
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 -
Method Summary
Modifier and TypeMethodDescriptionvoiddispose()Dispose the instance, removing all topics and listeners.doubleGet the number of subscribers for a topic.booleanChecks if instance has been disposed.booleanPublish a value to a topic asynchronously.voidreset()Reset the bus to its initial state without disposing it.voidsetDeliveryPolicy(EventDeliveryPolicy policy) Replace the runtime delivery policy used by future publications.org.angular.ts.ng.EventBusService.SubscriptionSubscribe a function to a topic.org.angular.ts.ng.EventBusService.SubscriptionsubscribeOnce(String topic, org.angular.ts.ng.EventBusService.EventBusListener fn) Subscribe a function to a topic only once.booleanunsubscribe(String topic, org.angular.ts.ng.EventBusService.EventBusListener fn) Unsubscribe a specific function from a topic.
-
Constructor Details
-
EventBusService
public EventBusService()
-
-
Method Details
-
dispose
public void dispose()Dispose the instance, removing all topics and listeners. -
getCount
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
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
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
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.
-