Thank you, Jens. Yes, I created only one EventBus and was passing it along
everywhere. But I was using eventBus = new SimpleEventBus();. I should have
used :
eventBus = new ResettableEventBus(new SimpleEventBus());
But it didn't give me any error. That means, ActivityManager checks if the
instance of EventBus is a Resettable one. Otherwise it would have thrown a
compilation or runtime error at
ActivityManager activityManager = new ActivityManager(activityMapper,
clientFactory.getEventBus());
So anyway, what I also understand from your response is that if I don't
need any cleaning in my Activity, there is no need to create a new one each
time (or I could call a reset() method in start(). But then I would be
going against a commonly used pattern.
JavaScript has garbage collection? I didn't know that.
thank you!
On Sunday, February 10, 2013 1:50:49 PM UTC-5, Jens wrote:
>
> 1. I understand that Activity instances are disposable but view instances
>> are not.
>>
>> 2. As a result of a place change, my ActivityMapper creates a new
>> Activity instance:
>> if (place instanceof LoginPlace)
>> return new LoginActivity((LoginPlace) place, clientFactory);
>>
>> Question: While it is true that Activity is supposed to be disposable, is
>> it really a good idea to create a new instance instead of reusing an
>> existing one? I.e. is it better to just do clientFactory.getHomeActivity()?
>>
>
> Activities are lightweight compared to widget/views because widget/views
> need to do DOM operations to construct themselves. Most people recreate
> activities so they dont have to care about their internal state. You always
> have a clean new instance and the old instance can be garbage collected.
>
> Views/Widget on the other hand my be cached/singleton if its worth it. For
> example if you have an endless scrolling list you dont want to create list
> entry widgets all the time. If you only see 20 entries at any time you
> maybe have a list of 30 entry widgets that are reused while scrolling.
>
>
>
> Now, as per the JavaDoc documentation of Activity,
>>
>> 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<http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/event/shared/HandlerRegistration.html>
>> instances
>> returned byEventBus.addHandler(com.google.gwt.event.shared.GwtEvent.Type,
>> H)<http://google-web-toolkit.googlecode.com/svn/javadoc/2.1/com/google/gwt/event/shared/EventBus.html#addHandler(com.google.gwt.event.shared.GwtEvent.Type,+H)>
>> .
>>
>> So, what I understand is that in the mayStop() method of my activity, I
>> don't have to do anything wrt the event handler. If the user goes back to
>> the same activity again, a new Activity instance will be created and a new
>> handler will be registered (since that code is in the constructor). The old
>> registration is automatically cleaned up.
>>
>
> The handler is only cleaned up automatically if you use the "special"
> EventBus provided in Activity.start(). The EventBus in the start() method
> is your application wide EventBus (the one you gave the ActivityManager)
> wrapped by a ResettableEventBus. Whenever you switch Activities the
> ActivityManager will reset the ResettableEventBus which causes all handlers
> being added by the activity to be deregistered.
>
>
> -- J.
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.