gwtgwtquerygquery

GwtQuery best practice


What is the best way to build a large app (really large) with GwtQuery

Any pointers shall be helpful


Solution

  • gQuery is not a framework, just a utility library which adds sugar syntax to Gwt java, so as you can deal with DOM using the popular jQuery API. It also adds some utilities like Promises, Easy Ajax, Json and Xml data binding etc.

    Said that, the best practices for gwtquery could be:

    1. Chose the final architecture in GWT you are happier with. You can use GWT plain widgets, or GWT MVP, GWTP, MGWT, GXT, Vaadin etc.
    2. Use gQuery to write less code for certain tasks
      • If you have to parse JSON or XML don't use gwt but gQuery builders
      • If you have to consume 3 party services or your app does not use rpc nor rf, use gQuery Ajax instead of dealing with RequestBuilder.
      • If you have very nested asynchronous code use gQuery Promises instead.
      • For drag and drop use gquery DnD plugin
      • To quick write something to console just use console.log instead of having to configure gwt loggers.
      • To avoid boiler plate of deferred binding per permutation just use if (Browser.isIE) ... and take advantage of code removal.
      • To include external JS in your compiled output use JsniBundler
      • To consume external JS methods use just JsUtils from gQuery
      • To add extra events to widgets or elements use GQuery.on(). Even you could replace the EventBus to fire custom events with data (better performance btw).
      • etc
    3. If you use any MVP pattern, use gQuery DOM manipulation in View implementations, and Ajax, Promises and Json parsing in your presenters so that you can test your code in JVM
    4. To enhance existing gwt widgets, don't extend them but modify their DOM structure with gQuery in your views, so as you can:
      • change and style the inner HTML
      • add missing behaviour adding new events etc.
      • overcome the Widget API limitation
    5. To create new Gwt widgets it could be much easier to do write gQuery plugin and optionally offer a Gwt API for non gwtquery users.
    6. If your app architecture is simple enough or you only have to deal with DOM and REST use just gwtquery for all: Rest consuming, UI, etc like you would do with jQuery

    We (Julien and me) gave an interesting presentation last year in the GWT.create 2013 conferences. You have the interactive slides or its static version, and I am giving a presentation speaking about gQuery and its best practices on the GWT.create 2015