The event bus that is passed to the start method is ResettableEventBus
created by the activity manager.  All event handlers registered with
this event bus will be removed before the onStop() is called. When a
view is re-used with another activity, the event bus passed to the
start() method will not have any handlers registered by the old
activity.  I think there should be no problem with handler
registration here unless I'm missing something.

On Dec 22, 6:38 pm, "[email protected]" <[email protected]> wrote:
> Hi everyone,
>
> Before 2.1 I created an application that use the "old" MVP
> architecture of having models, views and presenters. This worked quite
> well. I'm migrating this application to use the 2.1 MVP framework now.
> I've made some progress but am still getting my head around it.
>
> This has hit me so far: in my old code, the presenter was responsible
> for setting the listeners/handlers on the view/eventbus respectively.
> Where appropriate handlers would be removed when the view changed so
> that events are not handled more than once. (eg, I destroy my login
> window once login succeeds, and I also remove the eventbus
> LoginSucceededEvent handler, so after logging out there aren't two of
> them listening on the eventbus)
>
> Here is the start method of the apps' login activity:
> @Override
> public void start(AcceptsOneWidget panel, EventBus eventBus) {
>         LoginView view = clientFactory.getLoginView();  // just one instance
>         bindView(view);   // eg, view.getButton().addClickHandler(...
>         bindEvents(view, eventBus);   // eg, eventBus.addHandler(....
>         panel.setWidget(view.asWidget());
>
> }
>
> The LoginView is reused from the ClientFactory as the documentation
> suggests. This raises two questions:
>
> 1) I would like to keep the GUI bindings outside the UI code (just as
> I did in the old code where it was in the presenter). But since the
> documentation suggests using a single instance of a the views, here I
> would be adding more and more listeners each time the activity is
> initialised (as they are in the ActivityMapper). The HelloMVP example
> has the binding code in the view and allows the view to communicate
> with the activity. Can this be avoided? It would help in keeping the
> UI code strictly to UI and presentation. Short of implementing a
> method on all views that clear its listeners I cannot think of a
> better way (I would still think this to be cumbersome - its not
> something you'd normally do)
>
> 2) Similar issue with eventbus handlers - I can't wrap the eventbus in
> a ResettableEventBus as I don't want to wipe all handlers off the
> eventbus, nor do I want to have to manually deal with each handler in
> onStop of the Activity.
>
> I could have static fields in the activity to determine whether the
> binding has already been done, but that would eliminate the
> possibility of a view that might for whatever reason need to be re-
> created each time.
>
> Am I looking for a generic answer around the current 2.1 MVP framework
> where it doesn't exist?
>
> thanks
> Sunny

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to