Sunday, August 14, 2011

Issues with Code splitting using AsyncProvider interface of Gin

I am trying to do code splitting in my GWT application. Following MVP
pattern, I have a Presenter and View called TopPanelPresenter and
TopPanelViewer, which are instantiated in the application level
controller called AppPresenter. I have tried two approaches.

With one of the approaches (Using AsynProvider and Gin), there is some
part of TopPanelPresenter and TopPanelView in the leftover segment,
while with the second approach, there is nothing remaining in leftover
segment.

The 2 approaches should be doing the same thing, but I am getting
different results of code split for the class TopPanelPresenter.
Please guide me as to why this is happening, or am I using a wrong
version of Gin.

The following Gin Jars are present in my classpath
aopalliance.jar
gin-1.5-post-gwt-2.2.jar
guice-3.0-rc2.jar
guice-assistedinject-3.0-rc2.jar
guice-assistedinject-snapshot.jar
guice-servlet-3.0-rc2.jar
guice-snapshot.jar


Approach 1 - Using GIN and AsyncProvider
----------------------------------------------------------------
public class AppPresenter {

TopPanelPresenter topPanelPresenter = null;

private void loadTopPanel() {

EasyMedicalEntry.ginjector.getTopPanelPresenterAsyncProvider().get(new
AsyncCallback<TopPanelPresenter>() {
@Override
public void onFailure(Throwable caught) {}

@Override
public void onSuccess(TopPanelPresenter result) {
topPanelPresenter = result;
topPanelPresenter.bind();
view.setTopPanel(topPanelPresenter.getDisplay());
}
});
}
}

Approach 2
----------------
public class TopPanelPresenter {

// A callback for using the module instance once it's loaded
public interface ModuleClient {
void onSuccess(TopPanelPresenter instance);

void onUnavailable();
}

private TopPanelPresenter(EventBus bus, AppContext ctx) {
System.out.println("Entering TopPanelPresenter");
this.eventBus = bus;
this.display = new TopPanelViewer();
this.appCtx = ctx;
}

public static void createAsync(final EventBus bus, final AppContext
ctx,
final ModuleClient client) {
GWT.runAsync(new RunAsyncCallback() {
public void onFailure(Throwable err) {
client.onUnavailable();
}

public void onSuccess() {
if (instance == null) {
instance = new TopPanelPresenter(bus, ctx);

}
client.onSuccess(instance);
}
});
}

public class AppPresenter {

TopPanelPresenter topPanelPresenter = null;

private void loadTopPanel() {
TopPanelPresenter.createAsync(
eventBus, appCtx,
new TopPanelPresenter.ModuleClient() {
public void onSuccess(TopPanelPresenter presenter) {
topPanelPresenter = presenter;
topPanelPresenter.bind();
view.setTopPanel(topPanelPresenter.getDisplay());
}
@Override
public void onUnavailable() {
// TODO Auto-generated method stub
}
});
}
}

--
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-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate