我应该使用哪种GWT EventBus?

时间:2021-09-11 21:08:06

In the gwt-user.jar there are 2 EventBus interfaces and SimpleEventBus implmentations.

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

com.google.gwt.event.shared.EventBus and com.google.web.bindery.event.shared.EventBus I'll refer to these as 'gwt.event' and 'web.bindery'.

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

Looking at the JavaDocs and source code I can see that the gwt.event merely wraps the web.bindery one. However the gwt.event implementation also hides a number of deprecated methods

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

So which implementation should I use? (I'm on GWT 2.4)

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

4 个解决方案

#1


19  

Generally you should use the one in com.google.web.bindery. The only version used to be in com.google.gwt.event, but when RequestFactory and AutoBeans were moved out of GWT itself and into com.google.web.bindery so they could work in non-GWT clients.

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

If you use the com.google.web.bindery version in your presenters and such, it will make it easier to use outside GWT apps, should you need to. You'll also not get deprecation warnings when passing that instance to PlaceController and other classes that use EventBus.

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

#2


4  

I know this question has already an answer but might be worth while adding the following. As I said in my comment above, Activity still needs the com.google.gwt.event.shared.EventBus class. To avoid deprecated warnings, I did the following (I use GIN):

我知道这个问题已经有了答案,但在添加以下内容时可能值得。正如我在上面的评论中所说,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;
    }

...

By doing this, you will always be using the object from the "new" version of Event bus in the bindery package.

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

#3


2  

If you use Activities, then you'll probably have to use the deprecated one, at least until they clean up the whole API: http://code.google.com/p/google-web-toolkit/issues/detail?id=6653.

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

#4


0  

To make the choice even more complex. I am using guava in my GWT application and the google guys have added yet another EventBus in there (even less feature complete).

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

Maybe those guys need to sit together and define ONE implementation to rule them all ?

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

Obviously I would like to avoid all dependencies on GWT for code that is not strictly used in GWT code, so the Guava one looked interesting to me.

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

#1


19  

Generally you should use the one in com.google.web.bindery. The only version used to be in com.google.gwt.event, but when RequestFactory and AutoBeans were moved out of GWT itself and into com.google.web.bindery so they could work in non-GWT clients.

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

If you use the com.google.web.bindery version in your presenters and such, it will make it easier to use outside GWT apps, should you need to. You'll also not get deprecation warnings when passing that instance to PlaceController and other classes that use EventBus.

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

#2


4  

I know this question has already an answer but might be worth while adding the following. As I said in my comment above, Activity still needs the com.google.gwt.event.shared.EventBus class. To avoid deprecated warnings, I did the following (I use GIN):

我知道这个问题已经有了答案,但在添加以下内容时可能值得。正如我在上面的评论中所说,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;
    }

...

By doing this, you will always be using the object from the "new" version of Event bus in the bindery package.

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

#3


2  

If you use Activities, then you'll probably have to use the deprecated one, at least until they clean up the whole API: http://code.google.com/p/google-web-toolkit/issues/detail?id=6653.

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

#4


0  

To make the choice even more complex. I am using guava in my GWT application and the google guys have added yet another EventBus in there (even less feature complete).

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

Maybe those guys need to sit together and define ONE implementation to rule them all ?

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

Obviously I would like to avoid all dependencies on GWT for code that is not strictly used in GWT code, so the Guava one looked interesting to me.

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