checketts
checketts

Reputation: 14953

Which GWT EventBus should I use?

In the gwt-user.jar there are 2 EventBus interfaces and 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'.

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

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

Upvotes: 21

Views: 3885

Answers (4)

Christian Achilli
Christian Achilli

Reputation: 5707

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):

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.

Upvotes: 4

David Nouls
David Nouls

Reputation: 1895

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).

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.

Upvotes: 0

milan
milan

Reputation: 12402

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.

Upvotes: 2

Colin Alworth
Colin Alworth

Reputation: 18331

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.

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.

Upvotes: 19

Related Questions