关于减少 GWT、GXT、SmartGwt 等中的代码长度、JS 大小(加载时间)的想法

发布于 2024-10-08 05:51:07 字数 644 浏览 0 评论 0原文

让我们集思广益“我们可以做些什么来减少 GWT、GXT、SmartGWt 等中的代码大小?”

例如;使用按钮;

Button b = new Button();
b.setText("Ok");
b.setListener(this);
b.setEnabled(false);

Button b2 = new Button();
b2.setText("Ok2");
b2.setListener(this);
b2.setEnabled(false);

但是我们可以像工厂一样的模式来创建按钮。

public static createButton(String name, Listener listener, boolean enable){
    Button b = new Button();
    b.setText("Ok");
    b.setListener(this);
    b.setEnabled(false);
}

Button b = createButton("ok",this, false);
Button b2 = createButton("ok2",this, false);

对于更多按钮,我认为代码大小确实显示出差异,您对此示例有何看法?或者你有这样的想法吗?

Let's make brainstorm about "What could we do to reduce code size in GWT, GXT, SmartGWt etc.?"

For Example; To use a button;

Button b = new Button();
b.setText("Ok");
b.setListener(this);
b.setEnabled(false);

Button b2 = new Button();
b2.setText("Ok2");
b2.setListener(this);
b2.setEnabled(false);

But we could a pattern like factory to create button.

public static createButton(String name, Listener listener, boolean enable){
    Button b = new Button();
    b.setText("Ok");
    b.setListener(this);
    b.setEnabled(false);
}

Button b = createButton("ok",this, false);
Button b2 = createButton("ok2",this, false);

For more buttons I think code size really shows difference, What do you think about this example? Or have you any idea like this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千柳 2024-10-15 05:51:07

我认为创建按钮类是另一种解决方案

public class MyButton extends Button {
     private String text;
     private Listener l;
     private boolean enabled;
     ...
     ...
     ...

     public MyButton (String text, Listener l, boolean enable) {
           this.text = text;
           ....
     }
}

您也可以使用构建器模式创建 http://en.wikipedia.org /wiki/Builder_pattern 像这样

        new MyButton().setText("asd").setListener(l).setEnabled(false).senLength(343)..
 ..constructMyButton();

I think creating your button class is another solution

public class MyButton extends Button {
     private String text;
     private Listener l;
     private boolean enabled;
     ...
     ...
     ...

     public MyButton (String text, Listener l, boolean enable) {
           this.text = text;
           ....
     }
}

You can also create with Builder Pattern http://en.wikipedia.org/wiki/Builder_pattern like that

        new MyButton().setText("asd").setListener(l).setEnabled(false).senLength(343)..
 ..constructMyButton();
心舞飞扬 2024-10-15 05:51:07

如果您正在使用 GXT 开发应用程序,并且您的应用程序的语言与英语不同。您可以从应用程序定义区域设置,但在这种情况下,编译器会生成一种英语 JS 和一种您的区域设置 JS。以避免这种情况并减少编译时间。您可以从 com\extjs\gxt\ui\client\messages\XMessages.properties 替换区域设置消息内容,而不是使用 com\extjs\gxt\ui\client\messages\XMessages_it。属性

If your are developing aplications with GXT, and your application's language is different from English. You can define locale from application but in that case compiler generates one English JS and one your locale JS. To avoid this and reduce the compile time. You can replace your locales messages content from com\extjs\gxt\ui\client\messages\XMessages.properties instead of using com\extjs\gxt\ui\client\messages\XMessages_it.properties

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文