Comments inline.
On 01/20/2010 11:10 AM, Eduardo Nunes wrote:
> Comments inline.
>
> On Wed, Jan 20, 2010 at 3:54 PM, Jeff Chimene <[email protected]
> <mailto:[email protected]>> wrote:
>
> Comments inline.
>
> On 01/20/2010 10:06 AM, Eduardo Nunes wrote:
> > Comments inline.
> >
> > On Wed, Jan 20, 2010 at 2:46 PM, Jeff Chimene <[email protected]
> <mailto:[email protected]>
> > <mailto:[email protected] <mailto:[email protected]>>> wrote:
> >
> > Hi Eduardo:
> >
> > Comments inline.
> >
> > On 01/20/2010 09:34 AM, Eduardo Nunes wrote:
> > > I'm using a different approach, below a draft source code of my
> > > AppController class. What do you think?
> > >
> > > public class AppController implements
> ValueChangeHandler<String> {
> > >
> > > private final Map<String, PresenterType> urls;
> > > private final Map<PresenterType, Provider<? extends Presenter>>
> > presenters;
> > >
> > > @Inject
> > > public AppController() {
> > >
> > > urls = new TreeMap<String, PresenterType>();
> >
> > Could you expand a bit on why the choice of TreeMap vs.
> another HashMap?
> >
> >
> > Usually when I have a String as a key, I use TreeMap, it's faster
> to get
> > the information but slower to add. In this case the add process will
> > happen just once, so it's not a problem.
>
> Check.
>
> >
> >
> > > presenters = new HashMap<PresenterType, Provider<? extends
> > Presenter>>();
> > >
> > > urls.put("/contacts/list", PresenterType.CONTACT_LIST);
> > >
> > > History.addValueChangeHandler(this);
> > >
> > > }
> > >
> > > @Override
> > > public void onValueChange(ValueChangeEvent<String> event) {
> > >
> > > final PresenterType presenterType = urls.get(event.getValue());
> > >
> > > if (presenterType != null) {
> > >
> > > final Provider<? extends Presenter> presenter = presenters
> > > .get(presenterType);
> >
> > Is there a way to do this asynchronously at startup? I'm
> interested in
> > the shortest response time during event handling.
> >
> >
> > What do you mean by asynchronously in this case?
>
> Command(new IncrementalCommand(){}).
>
>
> you can change the implementation to something like this:
> public void onValueChange(ValueChangeEvent<String> event) {
>
> final PresenterType presenterType = urls.get(event.getValue());
>
> if (presenterType != null) {
>
> GWT.runAsync(new RunAsyncCallback() {
> @Override
> public void onSuccess() {
> final Provider<? extends Presenter> presenter = presenters
> .get(presenterType);
>
> final Presenter<? extends Display> instance = presenter
> .get();
> instance.bind();
>
> RootPanel.get().add(instance.getDisplay().asWidget());
> }
>
> @Override
> public void onFailure(Throwable reason) {
> }
> });
>
> }
>
> }
Good. Thanks for that.
>
> However, see the next comment.
>
> >
> >
> >
> > >
> > > final Presenter<? extends Display> instance = presenter.get();
> > > instance.bind();
> >
> > Ibid.
> >
> > >
> > > RootPanel.get().add(instance.getDisplay().asWidget());
> > >
> > > }
> > >
> > > }
> > >
> > > @Inject
> > > void
> configureContactListPresenter(Provider<ContactListPresenter>
> > > presenter) {
> > > presenters.put(PresenterType.CONTACT_LIST, presenter);
> >
> > Ibid. I don't understand why the get() can't be done here (i.e.
> > asynchronously at startup)
> >
> >
> > If I do the get, google-gin will create the whole object tree
> connected
> > to this presenter, in this case it will create the view too. This
> means
> > that at startup time, all presenters and views will be created,
> which in
> > my opinion isn't good.
Agreed. Just to be clear: even though there isn't a get() call, due to
gin magic, we still get instantiation of the
Provider<ContactListPresenter> presenter at startup time.
>
> OK. So the above ValueChange().get() returns a previously instantiated
> object. Negligable overhead when have maximum user attention. Check.
>
>
> Each time you call Provider.get() google-gin will check the scope of the
> object type, if I define that the ContactListPresenter has a SINGLETON
> scope, than the object will be instantiated just once, otherwise it will
> be instantiated in each call of Provider.get() method.
OK. I was thinking of gwt-mvp-sample (is that the name?) where there was
an idiom like
Presenter myPresenter = ensureMyPresenter();
Presenter ensureMyPresenter() {
if myPresenter == null {
myPresenter = myPresenter.get();
}
return myPresenter;
}
But I see that you've adopted gin + @singleton annotation to accomplish
the same results.
Check.
>
> I did some tests using the GWT.runAsync, it worked perfect in google
> chrome but it didn't work in IE7, I don't know why. I have a specific
> method configureNAME_OF_THE_PRESENTER for each presenter, due to the
> fact that I need google-gin to initialize them, otherwise I will have to
> initialize them by hand.
Why choose runAsync() over IncrementalCommand() (or to get closer to the
simple case of one action per Command(), DeferredCommand())?
Again, thanks for your detailed responses.
Cheers,
jec
--
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.