/Codes
//Sub-Module1 injector
@GinModules(M1Module.class)
public interface M1Injector extends Ginjector
{
Widget1 getWidget1();
}
//module
public class M1Module extends AbstractGinModule
{
@Override
protected void configure()
{
bind(Widget1.class).to(Widget1Impl.class);
}
}
//AsyncProvider
public class M1InjectorProvider implements AsyncProvider<M1Injector>
{
public void get(final AsyncCallback<M1Injector> asyncCallback)
{
GWT.runAsync(new RunAsyncCallback()
{
public void onSuccess()
{
asyncCallback.onSuccess((M1Injector)GWT.create(M1Injector.class));
}
public void onFailure(Throwable ex)
{
asyncCallback.onFailure(ex);
}
});
}
}
public interface Widget1 extends IsWidget
{
}
public class Widget1Impl extends Composite implements Widget1
{
private static Widget1ImplUiBinder uiBinder =
GWT.create(Widget1ImplUiBinder.class);
interface Widget1ImplUiBinder extends UiBinder<Widget, Widget1Impl>
{
}
public Widget1Impl()
{
initWidget(uiBinder.createAndBindUi(this));
}
}
//Sub-Module 2 Same pattern as above,just copy them and replace 1 with 2
//Global Module
@GinModules(Module.class)
public interface Injector extends Ginjector
{
static final Injector INSTANCE = GWT.create(Injector.class);
AsyncProvider<M1Injector> getM1InjectorProvider();
AsyncProvider<M2Injector> getM2InjectorProvider();
}
public class Module extends AbstractGinModule
{
@Override
protected void configure()
{
bind(new TypeLiteral<AsyncProvider<M1Injector>>()
{}).to(M1InjectorProvider.class);
bind(new
TypeLiteral<AsyncProvider<M2Injector>>(){}).to(M2InjectorProvider.class);
}
}
public class CodeSplit implements EntryPoint
{
/**
* This is the entry point method.
*/
private FlowPanel container;
private M1Injector mi;
private M2Injector m2i;
private Injector injector = GWT.create(Injector.class);
private Button bt;
public void onModuleLoad()
{
container = new FlowPanel();
container.add(bt = new Button("Load", new ClickHandler()
{
@Override
public void onClick(ClickEvent event)
{
doSomething();
}
}));
RootPanel.get().add(container);
}
private void doSomething()
{
if (container.getWidgetCount() == 1)
{
if (mi == null)
{
injector.getM1InjectorProvider().get(new
AsyncCallback<M1Injector>()
{
@Override
public void onFailure(Throwable caught)
{
// HP Auto-generated method stub
}
@Override
public void onSuccess(M1Injector result)
{
mi = result;
doSomething();
}
});
injector.getM2InjectorProvider().get(new
AsyncCallback<M2Injector>()
{
@Override
public void onFailure(Throwable caught)
{
// HP Auto-generated method stub
}
@Override
public void onSuccess(M2Injector result)
{
m2i = result;
doSomething();
}
});
} else
{
bt.setText("Unload");
container.add(mi.getWidget1());
container.add(m2i.getWidget2());
}
} else
{
bt.setText("Load");
container.remove(1);
}
}
}
And What confuse me is: if comments these two:
container.add(mi.getWidget1());
container.add(m2i.getWidget2());
all output goes to initial download,and if commenting one of them,the
other one got code split,this one not,if don't comments none of
them,code got split as expected. Anybody can tell me why,thanks?
--
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.