Java – the best GWT codesplitting design encapsulates “modules”

At present, I am facing a challenging problem related to GWT code segmentation. I hope to provide some help

I'm currently working on a large legacy GWT application (before MVP), and I'm looking for modules based on "portlets" (we call the various composite widgets we build pages) to split the code part of this application

At present, our module is only identified by the software package where the portlet is located, but I can change this to better adapt to a general code segmentation design

Any idea of how I design this code to indicate that the portlet / composite belongs to a specific "module", and then split the code so that any portlet / combination in module x is loaded for the first time, and the whole module x is loaded?

thank you

Solution

Well... Usually, it's simple, but I guess it's not your real problem?

Just use:

GWT.runAsync(new RunAsyncCallback() {
    public void onFailure(Throwable reason) {
        ...
    }
    public void onSuccess() {
        ...
    }
});

Then, everything in the onsuccess method will be split into another JavaScript file and loaded as needed

If you want to separate the composite from the rest of the code, just put the creation of the composite in the onsuccess method

You can also nest GWT Runasync method, so you can subdivide the part in different parts, for example First GWT Runasync loads module X. in the constructor of module x, you can execute another runasync and then load your composition

For cause, there may be some dependencies between parts, which makes it difficult for the compiler to split, but I have tested it with one of my projects (about 40K lines of code), and it works like a charm

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>