检查 GWT EventBus 是否有 EventHandler

Check if GWT EventBus has an EventHandler or not

每次使用以下行初始化视图时,我都会添加 EventHandler:

AGWTService.App.getEventBus().addHandler(AnEvent.TYPE, this.AClass);

这导致在应用程序的生命周期中处理多个事件。但是,没有方法可以从 EventBus 中删除处理程序或检查 EventBus 是否已经有 EventHandler。在我的例子中,EventBus 是一个静态的 SimpleEventBus class:

private static final EventBus EVENT_BUS = GWT.create(SimpleEventBus.class);

我尝试用 ResettableEventBus 包装 EventBus,但没有帮助。在 View 上处理 EventBus 的正确方法是什么。

addHandler() 方法 returns 一个 HandlerRegistration 的 removeHandler() 方法,您可以使用它来删除处理程序。