微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java – GWT EventBus中的大事件列表

在Google Web工具包提供的示例中,他们仅在整个应用程序的一个类中添加事件处理程序.

在 – 对于Module1,2和3中,所有事件都在主AppController类中注册.我觉得这有点单片,当我们使用MVP模式时,我们会在每个Presenters中声明一个名为bind()的方法,如下所示:

public class MyTestPresenter implements Presenter{

     private void bind()
     {
            TestEvent.eventBus.addHandler(TestEvent.Type,new TestEventHandlerImpl() )
     }

}


public class TestEvent
{
 public static SimpleEventBus eventBus = new SimpleEventBus()
}

查询是:

>如果我们的应用程序非常庞大 – 我们将使用一个事件总线来填充其中的一千多个事件 – 或者我们是否会以这样的方式设计我们为每个模块分别设置事件总线实例?
>保持静态事件总线字段的任何成本.任何更好的设计都可以将它的实例赋予所有类 – 通过构造函数将它传递给所有类,每个presenter类都有它的引用,这看起来有点杂乱……
>在事件处理方面,GWT的活动和地点是什么? – 有人可以指出如何理解活动/地方的概念吗?

解决方法

其实我也不喜欢GWT中的事件总线实现.我以前问过smt about.
现在我开发了一些桌面应用程序,然后以下一种方式设计eventBus.

public interface EventBus {
    void fireEvent(Event event);

    <T extends Event> void addHandler(Class<T> eventType,Handler<T> handler);

    interface Event {
    }

    interface Handler<E extends Event> {
        void handle(E event);
    }
}

因此,在通常的Java应用程序中,我会以其他方式设计它,但在这里我们应该处理与javascript相关的问题等等.

If our application is huge – we would
be using one eventbus to populate more
than a thousand events in it – or
would we design in such a way that we
have separate instances of event bus
for each module?.

我也在考虑这个问题.我发现没有任何真正的优势.对于模块化,您可以分离事件的可见性.而且有一些缺点.假设你应该在同一个类中处理几个eventBusses – 代码将是混乱的.除此之外,你应该以某种方式将这些实例映射到类.

Any cost of keeping the static event
bus field. Any better design to give
it’s instance to all classes – passing
it around to all classes through a
constructor with each presenter class
having it’s reference seems a bit of
clutter

你可以做到这两点.在新的Activity-Place框架中,它作为参数传递.

What are activity and places in GWT
when it comes to event handling? – Can
someone give a pointer to how to
understand the concept of
activity/place in general?

活动就像你的老主持人,但没有低级视图绑定.就像用于指定窗口的历史记录条目一样.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐