why EventBus in start method of Activity in 2.1

23 views
Skip to first unread message

Nicolas Antoniazzi

unread,
Nov 4, 2010, 4:46:12 AM11/4/10
to google-we...@googlegroups.com
Hello,

This is just a quick question to gwt developpers to know what is the reason to pass the EventBus to the start() method of Activity ?
Is there something special about this instance ?

Because if we use a ClientFactory, like described in the MVP doc on the website, (or we inject with Gin), we can get it. And get all other elements too (like PlaceController)

So I do not really understand what is the policy behind this. All elements should be passed (EventBus, PlaceController, ...) or none of them (then to rely on ClientFactory or Gin).
Why is athere a special mechanism for the EventBus ?

Thanks

Nicolas.

Thomas Broyer

unread,
Nov 4, 2010, 5:26:52 AM11/4/10
to Google Web Toolkit


On 4 nov, 09:46, Nicolas Antoniazzi <nicolas.antonia...@gmail.com>
wrote:
> Hello,
>
> This is just a quick question to gwt developpers to know what is the reason
> to pass the EventBus to the start() method of Activity ?
> Is there something special about this instance ?

Yes, it's actually a ResettableEventBus, so any handler added to it
will automatically be removed when the activity is stopped/cancelled,
and you don't have to track HandlerRegistrations yourself.
Here's what the Javadoc says:
"""Any handlers attached to the provided event bus will be de-
registered when the activity is stopped, so activities will rarely
need to hold on to the HandlerRegistration instances returned by
EventBus.addHandler(com.google.gwt.event.shared.GwtEvent.Type, H)."""
http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/activity/shared/Activity.html#start(com.google.gwt.user.client.ui.AcceptsOneWidget,
com.google.gwt.event.shared.EventBus)

Nicolas Antoniazzi

unread,
Nov 4, 2010, 5:57:31 AM11/4/10
to google-we...@googlegroups.com
Oh yes, that's nice.
It's great to wrap the original event bus so we can still use it to send fireEvent() and use the instance from start() to add new handler.
Very cool.

Thanks Thomas.

2010/11/4 Thomas Broyer <t.br...@gmail.com>

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


Matthew Hill

unread,
Dec 20, 2010, 6:38:04 PM12/20/10
to google-we...@googlegroups.com
So should we bother injecting an EventBus instance into the constructor or just use the instance provided by the start method?
Reply all
Reply to author
Forward
0 new messages