我应该使用哪种GWT EventBus?

在gwt-user.jar中有2个EventBus接口和SimpleEventBus implmentations。

com.google.gwt.event.shared.EventBuscom.google.web.bindery.event.shared.EventBus我将这些称为’gwt.event’和’web.bindery’。

查看JavaDocs和源代码,我可以看到gwt.event只包含web.bindery。 但是,gwt.event实现还隐藏了许多不推荐使用的方法

那么我应该使用哪种实现方式? (我在GWT 2.4上)

通常,您应该使用com.google.web.bindery那个。 以前唯一的版本是com.google.gwt.event ,但是当RequestFactory和AutoBeans从GWT本身移出并进入com.google.web.bindery ,它们可以在非GWT客户端中工作。

如果您在演示者中使用com.google.web.bindery版本等,则可以在需要时更轻松地使用外部GWT应用。 将该实例传递给PlaceController和其他使用EventBus的类时,您也不会收到弃用警告。

我知道这个问题已经有了答案,但在添加以下内容时可能值得。 正如我在上面的评论中所说,Activity仍然需要com.google.gwt.event.shared.EventBus类。 为了避免弃用警告,我做了以下(我使用GIN):

 public class GinClientModule extends AbstractGinModule { @Override protected void configure() { bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class); ... } @Provides @Singleton public com.google.gwt.event.shared.EventBus adjustEventBus( EventBus busBindery) { return (com.google.gwt.event.shared.EventBus) busBindery; } ... 

通过这样做,您将始终使用bindery包中“新”版本的Event总线中的对象。

如果您使用活动,那么您可能必须使用已弃用的活动,至少在他们清理整个API之前: http : //code.google.com/p/google-web-toolkit/issues/detail?id = 6653 。

使选择更加复杂。 我在我的GWT应用程序中使用guava,谷歌人在那里添加了另一个EventBus(甚至更少的function完成)。

也许这些人需要坐在一起定义一个实现来统治它们?

显然,我想避免GWT代码中没有严格使用的代码依赖于GWT,因此Guava对我来说很有趣。