I'm not entirely sure of your questions at the end, but it looks like
you're not using AsyncProvider the way it's intended and that might be
causing your problems.

AsyncProvider does not need to be bound to an implementation.
AsyncProvider should be managed by Gin.

public class MyModule extends AbstractGinModule {
     protected void configure()
  {
     bind(Widget1.class).to(Widget1Impl.class);
  }
}

@GinModules(MyModule.class)
public interface MyGinjector extends Ginjector {
   AsyncProvider<Widget1> getWidget1();
}

public class CodeSplit implements EntryPoint
{
    MyGinjector gin = GWT.create(MyGinjector.class);
    public void onModuleLoad()
    {
        RootPanel.get().add(new Button("Load", new ClickHandler() {
            public void onClick(ClickEvent event) {
               gin.getWidget1().get(new AsyncCallback<Widget1>() {
                   public void onFailure(Throwable caught) {}
                   public void onSuccess(Widget1 result) {
                       RootPanel.get().add(result);
                   }
               });
            }
}));
     }
 }

Hope that helps,
Derek

On Apr 14, 10:52 am, Alex Luya <alexander.l...@gmail.com> wrote:
> /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 google-web-toolkit@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.

Reply via email to