GWT EventBus 中的事件大列表

发布于 2024-11-06 18:34:40 字数 758 浏览 0 评论 0原文

在 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()
}

查询是:

  1. 如果我们的应用程序很大 - 我们 会更好吗?会使用一个事件总线来填充其中的一千多个事件 - 或者我们会以这样的方式设计,为每个模块都有单独的事件总线实例?

  2. 保留静态事件总线字段的任何成本。任何更好的设计将它的实例提供给所有类 - 通过构造函数将其传递给所有类,每个演示者类都有它的引用似乎有点混乱......

  3. 当涉及到事件时,GWT 中的活动和位置是什么处理? - 有人可以指导如何理解一般活动/地点的概念吗?

In the examples provided by Google Web toolkit that they are adding the event handlers in one class only for the whole application.

As in - for Module1, 2 and 3 all events are registered in the main AppController class. I find this a bit monolithic and would not it better when we are using the MVP pattern that we declare a method called bind() in each of the Presenters that is as follows:

public class MyTestPresenter implements Presenter{

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

}


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

Query is:

  1. 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?.

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

  3. 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

-小熊_ 2024-11-13 18:34:40

实际上我也不喜欢 GWT 中的事件总线实现。我之前曾向 smt 询问过有关
现在我开发一些桌面应用程序,并以下面的方式设计 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等相关的问题。

如果我们的应用程序很大 - 我们会
使用一个事件总线来填充更多事件总线
超过一千个事件 - 或者
我们会以这样的方式设计吗
有单独的事件总线实例
对于每个模块?.

我也在思考这个问题。我发现没有任何真正的优势。为了实现模块化,您可以分离事件的可见性。并且有一些缺点。假设您应该在同一个类中处理多个 eventBusses - 代码会很混乱。除此之外,您应该以某种方式将此实例映射到类。

保留静态事件的任何成本
总线领域。有什么更好的设计可以给
它是所有类的实例 - 传递
它通过一个
每个演示者类的构造函数
有它的参考似乎有点
混乱...

你可以两者都做。在新的 Activity-Place 框架中,它作为参数传递。

GWT 有哪些活动和地点
当涉及到事件处理时? - 能
有人指点一下如何
理解的概念
一般活动/地点?

Activity 就像您的旧演示者,但没有低级别视图绑定。就像用于指定窗口的历史条目一样放置。

Actually I dislike event bus implementation in GWT too. I've asked smt about before.
Now I develop some desktop application and I design eventBus in next way.

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

So in usual Java application I would design it in other way, but here we should deal with issues connected with javascript and so on.

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

I was thinking about this question too. I found that there are no any real advantages. For modularity you can separate visibility of your events. And there is some disadvantage. Suppose you should deal with several eventBusses in same class - code will be messy. Beside you should map this instances to classes somehow.

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

You can do both. In new Activity-Place framework it passed as parameter.

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?

Activity it's like your old presenter but without low level view binding. Place just like history entry that used for specify windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文