0

I am looking for example to use code splitting with gin and smartgwt ...

In my simple application I have 2 modules AutoLoadModule and WindowModule. In my simple app I just need to load a window when some button is clicked.

My window module contains:

@Override
protected void configure() {
    bind(MainWindow.class).in(Singleton.class);

}

and my MainWindow:

@Singleton
public class MainWindow extends Window implements SessionStatusChangedEvent.Handler {

    private final XmppSession session;

    @Inject
    private MainWindow(XmppSession session) {

        Log.debug("Constructor ImMainWindow... !");

        this.session = session;
        initComponent();
    }
    ....................

In my AutoLoadModule I have bind AutoLoad asEagerSingleton();

    @Override
    protected void configure() {
    bind(StartButton.class).toProvider(StartChatButtonProvider.class);
        bind(AutoLoader.class).asEagerSingleton();

    }

My AutoLoader class:

@Singleton
public class AutoLoader implements Scheduler.ScheduledCommand {

private final XmppConnection connection;
@Nullable
private final ImStartButton startButton;

    @Inject
    protected AutoLoader(final XmppConnection connection, final XmppSession session,
             final StartButton startButton) {
    this.startButton = startButton;

    Scheduler.get().scheduleDeferred(this);
    }

    @Override
    public final void execute() {
    startButton.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Log.debug("StartButton click handler...");
                    //load window in this point but how ? ....
        }
    });
    }
}

Its possible to load a window instance using Code Splitting, when window is in WindowModule? In my example app I need load the window only on demand using code splitting and that window must be in a gin module.

enrybo
  • 1,787
  • 1
  • 12
  • 20
Łukasz Woźniczka
  • 1,625
  • 3
  • 28
  • 51

1 Answers1

1

Not sure where you want to split your code, but using gin you can take advantage of AsyncProviders and let git to split your code.

@Inject
protected AutoLoader(
         final XmppConnection connection, 
         final XmppSession session,
         final StartButton startButton, 
         final AsyncProvider<MainWindow> mainProvider) {

  ...

  @Override
  public final void execute() {
    startButton.addClickHandler(new ClickHandler() {
      @Override
      public void onClick(ClickEvent event) {

        // Here Gin would split the code
        mainProvider.get(new AsyncCallback<MainWindow>() {
          public void onSuccess(MainWindow main) {
           ...
          }
        }

      }
    });
  }
Manolo Carrasco Moñino
  • 9,723
  • 1
  • 22
  • 27