Ideas for reducing code length, JS size (load time) in GWT, GXT, SmartGwt, etc.

Brainstorm about "What can we do to reduce code size in GWT, GXT, SmartGWt, etc.?"

For instance; To use the 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 create a factory type template to create a 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 the code size really shows the difference. What do you think of this example? Or do you have such an idea?

+3
source share
2 answers

GXT, . , JS JS. . locales com\extjs\gxt\ui\client\messages\XMessages.properties com\extjs\gxt\ui\client\messages\XMessages_it.properties

+1

, -

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;
           ....
     }
}

Builder http://en.wikipedia.org/wiki/Builder_pattern,

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

Source: https://habr.com/ru/post/1780829/


All Articles