Java – large event list in GWT eventbus

In the example provided by the Google Web toolkit, they add event handlers to only one class of the entire application

In – for module1, 2 and 3, all events are registered in the main AppController class I think this is a bit monolithic. When we use MVP mode, we will declare a method called bind () in each presenter, as shown below:

public class MyTestPresenter implements Presenter{

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

}


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

The query is:

>If our application is very large - we will use an event bus to fill in more than 1000 events - or will we design it in such a way that we set up event bus instances for each module? > Any cost of maintaining static event bus fields Any better design can assign its instance to all classes - pass it to all classes through the constructor, and each presenter class has its reference, which seems a little messy... > in terms of event processing, what is the activity and location of GWT? – Can anyone point out how to understand the concept of activity / place?

Solution

In fact, I don't like the event bus implementation in GWT I asked SMT about before

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

Therefore, in normal Java applications, I will design it in other ways, but here we should deal with JavaScript related problems and so on

I'm thinking about it, too I found no real advantage For modularity, you can separate the visibility of events And there are some shortcomings Suppose you should handle several eventbusses in the same class - the code will be messy In addition, you should map these instances to classes in some way

You can do both In the new activity place framework, it is passed as a parameter

The activity is like your old host, but there is no low-level view binding Just like the history entry used to specify the window

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>