开发者

Big list of events in GWT EventBus

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 t开发者_如何学运维he 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜