Comments inline. On Wed, Jan 20, 2010 at 3:54 PM, Jeff Chimene <[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]>> 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) { } }); } } 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. > > 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. 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. > 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 [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-web-toolkit%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-web-toolkit?hl=en. > > > > -- Eduardo S. Nunes http://enunes.org--
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.
