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 <jchim...@gmail.com > <mailto:jchim...@gmail.com>> 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(){}). 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. OK. So the above ValueChange().get() returns a previously instantiated object. Negligable overhead when have maximum user attention. Check. Still, I've noticed "some delay" at runtime w/ gin+mvp. I'd like to think that the implementation in this thread w/r/t/ configureContactListPresenter() could be handed to Command(new IncrementalCommand(){}). I'm choosing IncrementalCommand() because it seems that there will be more than one instantiating get() call. Maybe configurePresenters()? Perhaps that's an implementation detail best left to individual circumstances.
-- 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-web-tool...@googlegroups.com. To unsubscribe from this group, send email to google-web-toolkit+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.