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()
}
查询是:
如果我们的应用程序很大 - 我们 会更好吗?会使用一个事件总线来填充其中的一千多个事件 - 或者我们会以这样的方式设计,为每个模块都有单独的事件总线实例?
保留静态事件总线字段的任何成本。任何更好的设计将它的实例提供给所有类 - 通过构造函数将其传递给所有类,每个演示者类都有它的引用似乎有点混乱......
当涉及到事件时,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:
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?.
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 ...
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上我也不喜欢 GWT 中的事件总线实现。我之前曾向 smt 询问过有关。
现在我开发一些桌面应用程序,并以下面的方式设计 eventBus。
所以在通常的Java应用程序中我会以其他方式设计它,但这里我们应该处理与javascript等相关的问题。
我也在思考这个问题。我发现没有任何真正的优势。为了实现模块化,您可以分离事件的可见性。并且有一些缺点。假设您应该在同一个类中处理多个 eventBusses - 代码会很混乱。除此之外,您应该以某种方式将此实例映射到类。
你可以两者都做。在新的 Activity-Place 框架中,它作为参数传递。
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.
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.
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.
You can do both. In new Activity-Place framework it passed as parameter.
Activity it's like your old presenter but without low level view binding. Place just like history entry that used for specify windows.