4

我正在尝试在 MVP GWT 2.4 中使用 Gin。在我的模块中,我有:

import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.SimpleEventBus;

    @Override
      protected void configure() {
        bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
        ...
      }

上面的代码使用了新的com.google.web.bindery.event.shared.EventBus. 当我想在实现 Activity 的 MVP 活动中注入事件总线时,问题就来了:

package com.google.gwt.activity.shared;

import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

public interface Activity {

  ...

  void start(AcceptsOneWidget panel, EventBus eventBus);
}

Activity使用已弃用的com.google.gwt.event.shared.EventBus. 我怎样才能调和两者?显然,如果我要求使用已弃用的 EventBus 类型,那么 Gin 会抱怨,因为我没有为它指定绑定。

更新:这将允许应用程序构建,但现在有两个不同EventBus的 s,这很糟糕:

 protected void configure() {
    bind(com.google.gwt.event.shared.EventBus.class).to(
        com.google.gwt.event.shared.SimpleEventBus.class).in(Singleton.class);
    bind(EventBus.class).to(SimpleEventBus.class).in(Singleton.class);
    ...
4

4 回答 4

2

我问了一个类似的问题:我应该使用哪个 GWT EventBus?

您不需要弃用的事件总线,因为它扩展了 WebBindery 之一。

创建一个基本活动,您的活动都使用以下代码扩展:

// Forward to the web.bindery EventBus instead
@Override
@Deprecated
public void start(AcceptsOneWidget panel, com.google.gwt.event.shared.EventBus eventBus) {
   start(panel, (EventBus)eventBus);
}

public abstract void start(AcceptsOneWidget panel, EventBus eventBus);
于 2012-02-14T15:31:22.970 回答
2

为此记录了一个当前问题:http ://code.google.com/p/google-web-toolkit/issues/detail?id=6653

不幸的是,建议的解决方法是暂时坚持使用EventBus代码中已弃用的内容。

于 2012-02-13T22:55:21.760 回答
1

我认为更清洁的解决方案是:

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;
    }

...

请在此处参考我的回答

于 2013-06-06T00:16:03.273 回答
0

我发现将新旧版本绑定到同一个实例会有所帮助。

    /*
     * bind both versions of EventBus to the same single instance of the
     * SimpleEventBus
     */
    bind(SimpleEventBus.class).in(Singleton.class);
    bind(EventBus.class).to(SimpleEventBus.class);
    bind(com.google.gwt.event.shared.EventBus.class).to(SimpleEventBus.class);

现在,每当您的代码需要EventBus注入代码所需的代码并避免弃用警告时。

于 2013-01-30T17:01:53.283 回答