SlideShare a Scribd company logo
1 of 35
Download to read offline
Speed up your GWT coding with gQuery
Manuel Carrasco Moñino
GWT.create 2015
► Run these slides
1/35
About me...
Open Source advocate
Vaadin R&D
GWT Maintainer
Apache James PMC
Jenkins Committer
 
@dodotis
+ManuelCarrascoMoñino
2/35
What is gQuery?
Write less. Do more!
An entire GWT rewrite of the famous jQuery javascript library.
Use the jQuery API in GWT applications without including the jQuery,
while leveraging the optimizations and type safety provided by GWT.
3/35
It looks like jQuery
The API and syntax of GQuery is almost identical to jQuery.
Existing jQuery code can be easily adapted into GQuery and used in
your GWT applications.
jQuery gQuery
$(".article:not(.hidden)>.header")
.width($("#mainHeader").innerWidth())
.click(function(){
$(this)
.siblings(".content")
.load("/article/"+$(this).parent().id(),
null,
function(){
$(this).fadeIn(250);
});
});
importstaticcom.google.gwt.query.client.GQuery.*;
$(".article:not(.hidden)>.header")
.width($("#mainHeader").innerWidth())
.click(newFunction(){
publicvoidf(){
$(this)
.siblings(".content")
.load("/article/"+$(this).parent().id(),
null,
newFunction(){
publicvoidf(){
$(this).fadeIn(250);
}
});
}
});
4/35
But it's much more
It integrates gently with GWT
shares and enhances its event mechanism
knows about widgets hierarchy
GWT Optimizers
Provides a simpler deferred binding mechanism
Provide many utilities for GWT.
Plenty of useful methods
5/35
Current gQuery status
Very active development
3000 downloads per month
In the top 5 of the most popular GWT libraries
Stable versions since 2010
Official sponsored & supported by ArcBees
6/35
gQuery Fundamentals
7/35
Easy DOM manipulation
GQuery eases traversal and manipulation of the DOM.
Use $() to wrap, find and create elements or widgets
Chaining methods: select & modify several elements in just one line
of code.
friendly css style properties syntax.
Use $$() to set style properties or for animations
It also supports type safe CSS
$(".slides>section").css("background-color","green")
.animate($$("top:+80%"))
.animate($$("top:0,background-color:transparent")).size();
$("<p>Hello</p>").appendTo(".current");
8/35
Full GWT Widget integration
Whatever you do with elements, you can do with widgets
Query, Enhance, Manipulate, Modify
Promote elements to widgets inserting them in gwt hierarchy
Improve widgets events
Adding events not implemented by the widget
Buttonb=new Button("Clickme");
b.addClickHandler(new ClickHandler(){
publicvoidonClick(ClickEventevent){
console.log("ClickedonButton");
}
});
//PromoteanyDOMelementtoaGWTpanel
Panelp=$("section.current.jCode-div").as(Widgets).panel().widget();
//UseitasanyotherwidgetinGWThierarchy
p.add(b);
//EnhanceWidgetDOM
$("<ahref='javascript:'>Clickme</a>").prependTo($(b)).on("click",new Function(){
publicbooleanf(Evente){
console.log("ClickedonLink");
returnfalse;
}
});
9/35
Event Handling
Handle and fire any native event.
Create your own events.
Support for event name spaces.
Delegate events.
Pass data to listeners using events
Tip: Replacement to EventBus
console.log("Clickoncodetexttoseethefontcolor.");
$("#console").on("foo",new Function(){
publicbooleanf(Evente,Object...args){
console.log(args[0]);
returntrue;
}
});
$(".current.jCode").on("tap","span",new Function(){
publicbooleanf(Evente){
$("#console").trigger("foo",$(e).css("color"));
returnfalse;
}
});
10/35
Promises
GQuery implements the promises API existing in jQuery.
when, then, and, or, progress, done, fail, always
Use it as an alternative to nested callback based code.
Declarative syntax.
Can be used in the JVM
//Launchthingsatthesametimewithwhen
GQuery.when(
$(".ball.yellow").animate($$("bottom:0"),1000),
$(".ball.red").animate($$("bottom:0"),2000)
).done(new Function(){
publicvoidf(){
$(".ball").fadeOut();
}
});
11/35
Ajax
GQuery provides an easy API for Ajax.
Syntax sugar
Promises
Progress
Works in JVM
$("#response").load("gwtcreate2015.html#hello>div");
12/35
Data Binding
GQuery ships an easy data binding system to and from JSON or XML
Light weight implementation: each object wraps a JS object
JVM compatible.
publicinterfacePersonextendsJsonBuilder{
PersonsetName(Strings);
StringgetName();
PersonsetAge(inti);
intgetAge();
List<Person>getChildren();
PersongetPartner();
PersonsetPartner(Personp);
}
Personme=GQ.create(Person.class).setAge(10).setName("Manolo");
console.log(me);
13/35
Utilities
GQuery ships a set of GWT utilities which makes your live easier
Avoiding writing GWT JSNI
export, import
Simplifying GWT Deferred binding
browser.isIe, browser.isWebkit ... flags
Browser syntax logging
console.log, console.err ...
Import external JS in JSNIBlocks
JsniBundle
14/35
All Right, but how can gQuery help in my GWT project ?
Writing less code !
For certain actions you can save 60-90% of code
Making your code more expressive
Chaining is more declarative.
Promises try to solve nested and complex asynchronous blocks.
Using pure DOM elements instead of creating widgets for everything.
The tendency is to avoid Widgets
Web-components are here
Reusing existing code (js, html)
15/35
When can I use gQuery in my GWT project?
1.- Doesn't matter the final GWT architecture of your project
Plain GWT, MVP, GWTP
GXT, MGWT, Vaadin
2.- As usual separate Views from your Business logic.
In your Views: gQuery will help you to enhance & manipulate the DOM
In your Logic: you can use Ajax, Promises, and Json binding and test in the
JVM
16/35
I want to write less and do more...
Show me the code
17/35
Don't extend GWT widgets to change it's behavior.
Modify the widget when it attaches or detaches.
Modify its DOM
Add effects
Add events
Tip: when GWT attaches/detaches you must set events again
Easy to use in UiBinder classes
Widgetwidget=new Label("Hello");
widget.addAttachHandler(new Handler(){
publicvoidonAttachOrDetach(AttachEventevent){
$(event.getSource())
.append("<span>GWT</span><span>Create</span>")
.animate($$("y:+200px,x:+50px,color:yellow"),3000)
.on("click","span",new Function(){
publicvoidf(){
console.log($(this).text());
}
});
}
});
RootPanel.get().add(widget);
18/35
Decouple your widgets
Find any widget of a specific java class.
By default it looks for widgets attached to the RootPanel
Enclose your search using especific selectors like '.gwt-Label' or specific
contexts.
Then you can use those widgets as usual in your GWT application
//YougetalistwithallMyBreadCrumbmatchingtheselector
List<MyBreadCrumb>list=$(".gwt-Label").widgets(MyBreadCrumb.class);
MyBreadCrumbcrumbs=list.get(0);
crumbs.addCrumb("Rocks");
19/35
GWT Ajax never was simpler.
Just one line of code vs dozen of lines using RequestBuilder
Reusable responses via Promises
Advanced features
Upload/Download progress, FormData, CORS
Usable in the JVM
//ConfigurableviaPropertiessyntax
Ajax.get("/my-rest-service/items",$$("customer:whatever"));
Ajax.post("/my-rest-service/save",$$("id:foo,description:bar"));
Ajax.loadScript("/my-cdn-host/3party.js");
Ajax.importHtml("/bower_components/3party-web-component.html");
//OrviatheSettingsinterface
Ajax.ajax(Ajax.createSettings()
.setUrl("/my-3party-site/service")
.setWithCredentials(true)
.setData(GQ.create().set("parameter1","value")))
.fail(new Function(){
publicvoidf(){
console.log("Thecallshouldfailbecauseurl'sareinvalid");
}
});
20/35
Make your async code more declarative and simpler
Avoid nesting callbacks
Chain promises methods to add callbacks
Reuse resolved promises to avoid requesting twice the same service
resolved status is maintained for ever
Pipe your callbacks
//Wecanreusetheloginpromiseanytime
PromiseloginDone=Ajax.post("/my-login-service",$$("credentials:whatever"));
GQuery.when(loginDone)
.then(Ajax.post("/my-rest-service",$$().set("param","value")))
.done(new Function(){
publicObjectf(Object...args){
returnsuper.f(args);
}
}).fail(new Function(){
publicvoidf(){
console.log("LoginError");
}
});
21/35
JSNI sucks, how does gQuery help?
Export java functions to JS objects
This will be covered by JsInterop
But sometimes you will be interested on simply export one method
Execute external functions
Automatically boxes and un-boxes parameters and return values
Wrap any JS object with JsonBuilders
It supports functions
Load external libraries via JsniBundle
JsUtils.export(window,"foo",new Function(){
publicObjectf(Object...args){
returnargs[0];
}
});
Stringresponse=JsUtils.jsni(window,"foo","ByeByeJSNI");
console.log(response);
22/35
Simplifying deferred binding
gQuery Browser flags are set in compilation time.
They return true or false, making the compiler get rid of other borwsers
code
Not necessity of create classes nor deal with module files
if(browser.webkit){
console.log("WebKit");
}elseif(browser.ie6){
//Thiscodewillneverbeinchromepermutation
Window.alert("IE6doesnothaveconsole");
}else{
//Thiscodewillneverbeinchromepermutation
console.log("NotwebkitnorIE.Maybemozilla?"+browser.mozilla);
}
23/35
Extending gQuery
24/35
How to extend gQuery?
Plugins add new methods to GQuery objects
It's easy to call new methods via the as(Plugin) method
Plugins also could modify certain behaviors of gQuery:
support for new selectors
synthetic events
new css properties ...
publicstaticclassCss3AnimationsextendsGQuery{
//Wejustneedaconstructor,andareferencetothenewregisteredplugin
protectedCss3Animations(GQuerygq){
super(gq);
}
publicstaticfinalClass<Css3Animations>Css3Animations=GQuery
.registerPlugin(Css3Animations.class,new Plugin<Css3Animations>(){
publicCss3Animationsinit(GQuerygq){
returnnew Css3Animations(gq);
}
});
//Wecanaddnewmethodsoroverrideexistingones
publicCss3Animationscss3Animate(Propertiesproperties){
super.animate(properties);
returnthis;
}
}
$(".ball").as(Css3Animations.Css3Animations).animate($$("rotateX:180deg,rotateY:180deg"
25/35
How to port a jQuery plugin to gQuery
Gesture Plugin Differences
Take original JS code
Create JsBuider interfaces so as syntax is similar to JS
Set appropriate java types to JS variables
Gesture Plugin Source Gighub
Gesture Plugin Demo
$(".current.jCode").as(Gesture.Gesture).on("taptwo",new Function(){
publicvoidf(){
console.log("DoubleTap");
}
});
26/35
What is the future of gQuery
Type safe functions and promises
Full support for java 8 lambdas
Mobile friendly
Integration with JsInterop
GQueryg=$(".ball");
g.each(new IsElementFunction(){
publicvoidrun(Elementelm){
$(elm).animate("scale:1.2");
}
});
g.on("tapone",new IsEventFunction(){
publicBooleancall(Eventevt){
return$(evt).animate($$("rotateX:90deg")).animate($$("rotateX:0deg")).FALSE;
}
});
//PredefinedreturntypesinthegQuerychain
g.on("taptwo",(e)->$(e).animate($$("x:+=50")).TRUE);
//Gettheresultofmultiplecallbacks
$.when(()->"aaa",()->"bbb",Ajax.get("/lambdas.html"))
.done((Object[]s)->console.log(s[0],s[1],s[3]))
.fail((s)->console.log("Fail"));
27/35
Show me more cool code ...
28/35
Example: Material Design Hierarchical Timing.
boxes.each(new Function(){
intscale=boxes.isVisible()?0:1;
publicvoidf(Elemente){
GQueryg=$(this);
intdelay=(int)(g.offset().left+g.offset().top);
g.animate("duration:200,delay:"+delay+",scale:"+scale);
}
});
29/35
Example: Material Design Ripple Effect.
//Createtherippleelementtobeanimated
finalGQueryripple=$("<div>").as(Transitions.Transitions).css(
$$("position:absolute,width:40px,height:40px,background:white,border-radius:50%"
//Addrippleeffectstocertainelementswhentheyaretapped
$(".jCode,.button,h1").on("tap.ripple",new Function(){
publicbooleanf(Evente){
GQuerytarget=$(this).css($$("overflow:hidden")).append(ripple);
intx=e.getClientX()-20-target.offset().left;
inty=e.getClientY()-20-target.offset().top;
intf=Math.max(target.width(),target.height())/40*3;
ripple.css($$("opacity:0.8,scale:0.5")).css("left",x+"px").css("top",y+"px");
ripple.animate($$("opacity:0,scale:"+f),new Function(){
publicvoidf(){
ripple.detach();
}
});
returnfalse;
}
});
30/35
Example: Wrapping Web Components with gQuery
Use bower to install components in the public folder
bower install Polymer/paper-slider
Use Ajax utility methods to load polyfills and import templates
Web Components can be created and manipulated as any other
element.
We can change its properties or bind events.
Ajax.loadScript("bower_components/webcomponentsjs/webcomponents.js");
Ajax.importHtml("bower_components/paper-slider/paper-slider.html");
GQueryslider=$("<paper-slider/>").appendTo($("#sliders-container"));
slider.prop("value",67);
slider.on("change",(e)->{
console.log($(e).prop("value"));
returntrue;
});
$("#sliders-container").append("<paper-slidervalue=183max=255editable>");
31/35
Example: Binding Attributes of Web Components.
JsonBuilder can wrap any JavaScript element
Light Weight wrapper
Type safe
Chain setters
publicinterfacePaperSliderextendsJsonBuilder{
//get/setprefixesareoptional
intgetValue();
//Chainingsettersisoptional
PaperSlidersetValue(intvalue);
PaperSlidermin(intvalue);
PaperSlidermax(intvalue);
PaperSliderstep(intvalue);
PaperSlidersnaps(booleanvalue);
PaperSliderpin(booleanvalue);
}
//Waituntilthepolyfillandthewebcomponenthasbeenloaded
GQuery.when(
Ajax.loadScript("bower_components/webcomponentsjs/webcomponents.js"),
Ajax.importHtml("bower_components/paper-slider/paper-slider.html")
).done(new Function(){
publicvoidf(){
//CreateandappendtheelementasusualingQuery
GQueryg=$("<paper-slider>").appendTo($("#slider-container"));
//WrapthenativeelementinaPOJO
PaperSliderslider=GQ.create(PaperSlider.class).load(g);
//Useitasajavaobject
slider.setValue(300).max(400).step(50).snaps(true).pin(true);
}
});
32/35
Example: Uploading files with progress bar.
finalGQueryprogress=$("<div>").css($$("height:12px,width:0%,background:#75bff4,position:absolu
finalGQueryfileUpload=$("<inputtype='file'accept='image/*'>").appendTo(document).hide
fileUpload.on("change",new Function(){
publicbooleanf(Evente){
finalJsArray<JavaScriptObject>files=$(e).prop("files");
JavaScriptObjectformData=JsUtils.jsni("eval","newFormData()");
for(inti=0,l=files.length();i<l;i++){
JsUtils.jsni(formData,"append","file-"+i,files.get(i));
}
Ajax.ajax(Ajax.createSettings()
.setUrl(uploadUrl).setData(formData).setWithCredentials(true))
.progress(new Function(){
publicvoidf(){
progress.animate("width:"+arguments(2)+"%",1000);
}
}).always(new Function(){
publicvoidf(){
progress.remove();
}
}).done(new Function(){
publicvoidf(){
uploadImg.attr("src",uploadUrl+"&show=file-0-0");
}
});
returntrue;
}
}).trigger("click");
33/35
Real Examples
www.GwtProject.org
www.Arcbees.com
GwtQuery Slides
www.Talkwheel.com
34/35
Questions and Answers
Rate this talk: http://gwtcreate.com/agenda
when(()->"Talk")
.then((o)->"Questions")
.and((o)->"Answers")
.done((o)->console.log("Thanks"));
35/35

More Related Content

What's hot

Vaadin Components @ Angular U
Vaadin Components @ Angular UVaadin Components @ Angular U
Vaadin Components @ Angular UJoonas Lehtinen
 
The Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScriptThe Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScriptTim Perry
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module PatternsNicholas Jansma
 
GWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicGWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicCristiano Costantini
 
A friend in need - A JS indeed
A friend in need - A JS indeedA friend in need - A JS indeed
A friend in need - A JS indeedYonatan Levin
 
Difference between java script and jquery
Difference between java script and jqueryDifference between java script and jquery
Difference between java script and jqueryUmar Ali
 
"Migrate large gwt applications - Lessons Learned" By Harald Pehl
"Migrate large gwt applications - Lessons Learned" By Harald Pehl"Migrate large gwt applications - Lessons Learned" By Harald Pehl
"Migrate large gwt applications - Lessons Learned" By Harald PehlGWTcon
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJSFITC
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & VuexBernd Alter
 
Sword fighting with Dagger GDG-NYC Jan 2016
 Sword fighting with Dagger GDG-NYC Jan 2016 Sword fighting with Dagger GDG-NYC Jan 2016
Sword fighting with Dagger GDG-NYC Jan 2016Mike Nakhimovich
 
Gwt.Create Keynote San Francisco
Gwt.Create Keynote San FranciscoGwt.Create Keynote San Francisco
Gwt.Create Keynote San FranciscoRay Cromwell
 
GWT Introduction and Overview - SV Code Camp 09
GWT Introduction and Overview - SV Code Camp 09GWT Introduction and Overview - SV Code Camp 09
GWT Introduction and Overview - SV Code Camp 09Fred Sauer
 
Using ReactJS in AngularJS
Using ReactJS in AngularJSUsing ReactJS in AngularJS
Using ReactJS in AngularJSBoris Dinkevich
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web ComponentsAndrew Rota
 
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?Srijan Technologies
 
GWT Training - Session 2/3
GWT Training - Session 2/3GWT Training - Session 2/3
GWT Training - Session 2/3Faiz Bashir
 

What's hot (20)

Vaadin Components @ Angular U
Vaadin Components @ Angular UVaadin Components @ Angular U
Vaadin Components @ Angular U
 
The Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScriptThe Many Ways to Build Modular JavaScript
The Many Ways to Build Modular JavaScript
 
React
React React
React
 
Javascript Module Patterns
Javascript Module PatternsJavascript Module Patterns
Javascript Module Patterns
 
GWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 PanicGWTcon 2015 - Beyond GWT 3.0 Panic
GWTcon 2015 - Beyond GWT 3.0 Panic
 
A friend in need - A JS indeed
A friend in need - A JS indeedA friend in need - A JS indeed
A friend in need - A JS indeed
 
Difference between java script and jquery
Difference between java script and jqueryDifference between java script and jquery
Difference between java script and jquery
 
"Migrate large gwt applications - Lessons Learned" By Harald Pehl
"Migrate large gwt applications - Lessons Learned" By Harald Pehl"Migrate large gwt applications - Lessons Learned" By Harald Pehl
"Migrate large gwt applications - Lessons Learned" By Harald Pehl
 
Vaadin Components
Vaadin ComponentsVaadin Components
Vaadin Components
 
Building a Startup Stack with AngularJS
Building a Startup Stack with AngularJSBuilding a Startup Stack with AngularJS
Building a Startup Stack with AngularJS
 
Introduction to VueJS & Vuex
Introduction to VueJS & VuexIntroduction to VueJS & Vuex
Introduction to VueJS & Vuex
 
Sword fighting with Dagger GDG-NYC Jan 2016
 Sword fighting with Dagger GDG-NYC Jan 2016 Sword fighting with Dagger GDG-NYC Jan 2016
Sword fighting with Dagger GDG-NYC Jan 2016
 
Gwt.Create Keynote San Francisco
Gwt.Create Keynote San FranciscoGwt.Create Keynote San Francisco
Gwt.Create Keynote San Francisco
 
GWT Introduction and Overview - SV Code Camp 09
GWT Introduction and Overview - SV Code Camp 09GWT Introduction and Overview - SV Code Camp 09
GWT Introduction and Overview - SV Code Camp 09
 
Using ReactJS in AngularJS
Using ReactJS in AngularJSUsing ReactJS in AngularJS
Using ReactJS in AngularJS
 
Vue business first
Vue business firstVue business first
Vue business first
 
The Complementarity of React and Web Components
The Complementarity of React and Web ComponentsThe Complementarity of React and Web Components
The Complementarity of React and Web Components
 
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
[Srijan Wednesday Webinar] Rails 5: What's in It for Me?
 
AngularJS
AngularJSAngularJS
AngularJS
 
GWT Training - Session 2/3
GWT Training - Session 2/3GWT Training - Session 2/3
GWT Training - Session 2/3
 

Similar to Speed up your GWT coding with gQuery

Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Thinqloud
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQueryPhDBrown
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentationMevin Mohan
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretssmueller_sandsmedia
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instrumentsArtem Nagornyi
 
Vaadin 7 CN
Vaadin 7 CNVaadin 7 CN
Vaadin 7 CNjojule
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScriptAndrew Dupont
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegapyangdj
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaveryangdj
 
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 BejugEnterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejugrobbiev
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developersPavel Lahoda
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon Berlin
 

Similar to Speed up your GWT coding with gQuery (20)

Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
Introduction to jQuery
Introduction to jQueryIntroduction to jQuery
Introduction to jQuery
 
droidQuery: The Android port of jQuery
droidQuery: The Android port of jQuerydroidQuery: The Android port of jQuery
droidQuery: The Android port of jQuery
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Jquery presentation
Jquery presentationJquery presentation
Jquery presentation
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
Web UI test automation instruments
Web UI test automation instrumentsWeb UI test automation instruments
Web UI test automation instruments
 
Vaadin 7 CN
Vaadin 7 CNVaadin 7 CN
Vaadin 7 CN
 
J query training
J query trainingJ query training
J query training
 
Writing Maintainable JavaScript
Writing Maintainable JavaScriptWriting Maintainable JavaScript
Writing Maintainable JavaScript
 
jQuery
jQueryjQuery
jQuery
 
Blockly
BlocklyBlockly
Blockly
 
jQuery for web development
jQuery for web developmentjQuery for web development
jQuery for web development
 
After max+phonegap
After max+phonegapAfter max+phonegap
After max+phonegap
 
混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver混搭移动开发:PhoneGap+JQurey+Dreamweaver
混搭移动开发:PhoneGap+JQurey+Dreamweaver
 
Enterprise Guice 20090217 Bejug
Enterprise Guice 20090217 BejugEnterprise Guice 20090217 Bejug
Enterprise Guice 20090217 Bejug
 
Improving android experience for both users and developers
Improving android experience for both users and developersImproving android experience for both users and developers
Improving android experience for both users and developers
 
Droidcon2013 android experience lahoda
Droidcon2013 android experience lahodaDroidcon2013 android experience lahoda
Droidcon2013 android experience lahoda
 
Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 
jQuery
jQueryjQuery
jQuery
 

More from Manuel Carrasco Moñino

Present and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspectivePresent and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspectiveManuel Carrasco Moñino
 
GwtQuery the perfect companion for GWT, GWT.create 2013
GwtQuery the perfect companion for GWT,  GWT.create 2013GwtQuery the perfect companion for GWT,  GWT.create 2013
GwtQuery the perfect companion for GWT, GWT.create 2013Manuel Carrasco Moñino
 
Rapid and Reliable Developing with HTML5 & GWT
Rapid and Reliable Developing with HTML5 & GWTRapid and Reliable Developing with HTML5 & GWT
Rapid and Reliable Developing with HTML5 & GWTManuel Carrasco Moñino
 
GWT: Why GWT, GQuery, and RequestFactory
GWT: Why GWT, GQuery, and RequestFactoryGWT: Why GWT, GQuery, and RequestFactory
GWT: Why GWT, GQuery, and RequestFactoryManuel Carrasco Moñino
 
Gwt seminario java_hispano_manolocarrasco
Gwt seminario java_hispano_manolocarrascoGwt seminario java_hispano_manolocarrasco
Gwt seminario java_hispano_manolocarrascoManuel Carrasco Moñino
 

More from Manuel Carrasco Moñino (20)

The Java alternative to Javascript
The Java alternative to JavascriptThe Java alternative to Javascript
The Java alternative to Javascript
 
GWT and PWA
GWT and PWAGWT and PWA
GWT and PWA
 
Present and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspectivePresent and Future of GWT from a developer perspective
Present and Future of GWT from a developer perspective
 
GWT Contributor Workshop
GWT Contributor WorkshopGWT Contributor Workshop
GWT Contributor Workshop
 
CRUD with Polymer 2.0
CRUD with Polymer 2.0CRUD with Polymer 2.0
CRUD with Polymer 2.0
 
Web Components and PWA
Web Components and PWAWeb Components and PWA
Web Components and PWA
 
Building Components for Business Apps
Building Components for Business AppsBuilding Components for Business Apps
Building Components for Business Apps
 
Vaadin codemotion 2014
Vaadin codemotion 2014Vaadin codemotion 2014
Vaadin codemotion 2014
 
GwtQuery the perfect companion for GWT, GWT.create 2013
GwtQuery the perfect companion for GWT,  GWT.create 2013GwtQuery the perfect companion for GWT,  GWT.create 2013
GwtQuery the perfect companion for GWT, GWT.create 2013
 
Rapid and Reliable Developing with HTML5 & GWT
Rapid and Reliable Developing with HTML5 & GWTRapid and Reliable Developing with HTML5 & GWT
Rapid and Reliable Developing with HTML5 & GWT
 
Aprendiendo GWT
Aprendiendo GWTAprendiendo GWT
Aprendiendo GWT
 
Apache James/Hupa & GWT
Apache James/Hupa & GWTApache James/Hupa & GWT
Apache James/Hupa & GWT
 
GWT: Why GWT, GQuery, and RequestFactory
GWT: Why GWT, GQuery, and RequestFactoryGWT: Why GWT, GQuery, and RequestFactory
GWT: Why GWT, GQuery, and RequestFactory
 
Mod security
Mod securityMod security
Mod security
 
Gwt IV -mvp
Gwt IV -mvpGwt IV -mvp
Gwt IV -mvp
 
Gwt III - Avanzado
Gwt III - AvanzadoGwt III - Avanzado
Gwt III - Avanzado
 
Gwt II - trabajando con gwt
Gwt II - trabajando con gwtGwt II - trabajando con gwt
Gwt II - trabajando con gwt
 
Gwt I - entendiendo gwt
Gwt I - entendiendo gwtGwt I - entendiendo gwt
Gwt I - entendiendo gwt
 
Seguridad en redes de computadores
Seguridad en redes de computadoresSeguridad en redes de computadores
Seguridad en redes de computadores
 
Gwt seminario java_hispano_manolocarrasco
Gwt seminario java_hispano_manolocarrascoGwt seminario java_hispano_manolocarrasco
Gwt seminario java_hispano_manolocarrasco
 

Recently uploaded

Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSebastiano Panichella
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringSebastiano Panichella
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxJohnree4
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...NETWAYS
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...NETWAYS
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptssuser319dad
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxmavinoikein
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxFamilyWorshipCenterD
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSebastiano Panichella
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationNathan Young
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptxBasil Achie
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@vikas rana
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...NETWAYS
 
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)Basil Achie
 

Recently uploaded (20)

Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with AerialistSimulation-based Testing of Unmanned Aerial Vehicles with Aerialist
Simulation-based Testing of Unmanned Aerial Vehicles with Aerialist
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 
The 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software EngineeringThe 3rd Intl. Workshop on NL-based Software Engineering
The 3rd Intl. Workshop on NL-based Software Engineering
 
Genshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptxGenshin Impact PPT Template by EaTemp.pptx
Genshin Impact PPT Template by EaTemp.pptx
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Rohini Delhi 💯Call Us 🔝8264348440🔝
 
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
Open Source Camp Kubernetes 2024 | Monitoring Kubernetes With Icinga by Eric ...
 
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
OSCamp Kubernetes 2024 | SRE Challenges in Monolith to Microservices Shift at...
 
Philippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.pptPhilippine History cavite Mutiny Report.ppt
Philippine History cavite Mutiny Report.ppt
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
Work Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptxWork Remotely with Confluence ACE 2.pptx
Work Remotely with Confluence ACE 2.pptx
 
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptxGenesis part 2 Isaiah Scudder 04-24-2024.pptx
Genesis part 2 Isaiah Scudder 04-24-2024.pptx
 
SBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation TrackSBFT Tool Competition 2024 -- Python Test Case Generation Track
SBFT Tool Competition 2024 -- Python Test Case Generation Track
 
The Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism PresentationThe Ten Facts About People With Autism Presentation
The Ten Facts About People With Autism Presentation
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
LANDMARKS  AND MONUMENTS IN NIGERIA.pptxLANDMARKS  AND MONUMENTS IN NIGERIA.pptx
LANDMARKS AND MONUMENTS IN NIGERIA.pptx
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@call girls in delhi malviya nagar @9811711561@
call girls in delhi malviya nagar @9811711561@
 
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
Open Source Camp Kubernetes 2024 | Running WebAssembly on Kubernetes by Alex ...
 
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
NATIONAL ANTHEMS OF AFRICA (National Anthems of Africa)
 

Speed up your GWT coding with gQuery

  • 1. Speed up your GWT coding with gQuery Manuel Carrasco Moñino GWT.create 2015 ► Run these slides 1/35
  • 2. About me... Open Source advocate Vaadin R&D GWT Maintainer Apache James PMC Jenkins Committer   @dodotis +ManuelCarrascoMoñino 2/35
  • 3. What is gQuery? Write less. Do more! An entire GWT rewrite of the famous jQuery javascript library. Use the jQuery API in GWT applications without including the jQuery, while leveraging the optimizations and type safety provided by GWT. 3/35
  • 4. It looks like jQuery The API and syntax of GQuery is almost identical to jQuery. Existing jQuery code can be easily adapted into GQuery and used in your GWT applications. jQuery gQuery $(".article:not(.hidden)>.header") .width($("#mainHeader").innerWidth()) .click(function(){ $(this) .siblings(".content") .load("/article/"+$(this).parent().id(), null, function(){ $(this).fadeIn(250); }); }); importstaticcom.google.gwt.query.client.GQuery.*; $(".article:not(.hidden)>.header") .width($("#mainHeader").innerWidth()) .click(newFunction(){ publicvoidf(){ $(this) .siblings(".content") .load("/article/"+$(this).parent().id(), null, newFunction(){ publicvoidf(){ $(this).fadeIn(250); } }); } }); 4/35
  • 5. But it's much more It integrates gently with GWT shares and enhances its event mechanism knows about widgets hierarchy GWT Optimizers Provides a simpler deferred binding mechanism Provide many utilities for GWT. Plenty of useful methods 5/35
  • 6. Current gQuery status Very active development 3000 downloads per month In the top 5 of the most popular GWT libraries Stable versions since 2010 Official sponsored & supported by ArcBees 6/35
  • 8. Easy DOM manipulation GQuery eases traversal and manipulation of the DOM. Use $() to wrap, find and create elements or widgets Chaining methods: select & modify several elements in just one line of code. friendly css style properties syntax. Use $$() to set style properties or for animations It also supports type safe CSS $(".slides>section").css("background-color","green") .animate($$("top:+80%")) .animate($$("top:0,background-color:transparent")).size(); $("<p>Hello</p>").appendTo(".current"); 8/35
  • 9. Full GWT Widget integration Whatever you do with elements, you can do with widgets Query, Enhance, Manipulate, Modify Promote elements to widgets inserting them in gwt hierarchy Improve widgets events Adding events not implemented by the widget Buttonb=new Button("Clickme"); b.addClickHandler(new ClickHandler(){ publicvoidonClick(ClickEventevent){ console.log("ClickedonButton"); } }); //PromoteanyDOMelementtoaGWTpanel Panelp=$("section.current.jCode-div").as(Widgets).panel().widget(); //UseitasanyotherwidgetinGWThierarchy p.add(b); //EnhanceWidgetDOM $("<ahref='javascript:'>Clickme</a>").prependTo($(b)).on("click",new Function(){ publicbooleanf(Evente){ console.log("ClickedonLink"); returnfalse; } }); 9/35
  • 10. Event Handling Handle and fire any native event. Create your own events. Support for event name spaces. Delegate events. Pass data to listeners using events Tip: Replacement to EventBus console.log("Clickoncodetexttoseethefontcolor."); $("#console").on("foo",new Function(){ publicbooleanf(Evente,Object...args){ console.log(args[0]); returntrue; } }); $(".current.jCode").on("tap","span",new Function(){ publicbooleanf(Evente){ $("#console").trigger("foo",$(e).css("color")); returnfalse; } }); 10/35
  • 11. Promises GQuery implements the promises API existing in jQuery. when, then, and, or, progress, done, fail, always Use it as an alternative to nested callback based code. Declarative syntax. Can be used in the JVM //Launchthingsatthesametimewithwhen GQuery.when( $(".ball.yellow").animate($$("bottom:0"),1000), $(".ball.red").animate($$("bottom:0"),2000) ).done(new Function(){ publicvoidf(){ $(".ball").fadeOut(); } }); 11/35
  • 12. Ajax GQuery provides an easy API for Ajax. Syntax sugar Promises Progress Works in JVM $("#response").load("gwtcreate2015.html#hello>div"); 12/35
  • 13. Data Binding GQuery ships an easy data binding system to and from JSON or XML Light weight implementation: each object wraps a JS object JVM compatible. publicinterfacePersonextendsJsonBuilder{ PersonsetName(Strings); StringgetName(); PersonsetAge(inti); intgetAge(); List<Person>getChildren(); PersongetPartner(); PersonsetPartner(Personp); } Personme=GQ.create(Person.class).setAge(10).setName("Manolo"); console.log(me); 13/35
  • 14. Utilities GQuery ships a set of GWT utilities which makes your live easier Avoiding writing GWT JSNI export, import Simplifying GWT Deferred binding browser.isIe, browser.isWebkit ... flags Browser syntax logging console.log, console.err ... Import external JS in JSNIBlocks JsniBundle 14/35
  • 15. All Right, but how can gQuery help in my GWT project ? Writing less code ! For certain actions you can save 60-90% of code Making your code more expressive Chaining is more declarative. Promises try to solve nested and complex asynchronous blocks. Using pure DOM elements instead of creating widgets for everything. The tendency is to avoid Widgets Web-components are here Reusing existing code (js, html) 15/35
  • 16. When can I use gQuery in my GWT project? 1.- Doesn't matter the final GWT architecture of your project Plain GWT, MVP, GWTP GXT, MGWT, Vaadin 2.- As usual separate Views from your Business logic. In your Views: gQuery will help you to enhance & manipulate the DOM In your Logic: you can use Ajax, Promises, and Json binding and test in the JVM 16/35
  • 17. I want to write less and do more... Show me the code 17/35
  • 18. Don't extend GWT widgets to change it's behavior. Modify the widget when it attaches or detaches. Modify its DOM Add effects Add events Tip: when GWT attaches/detaches you must set events again Easy to use in UiBinder classes Widgetwidget=new Label("Hello"); widget.addAttachHandler(new Handler(){ publicvoidonAttachOrDetach(AttachEventevent){ $(event.getSource()) .append("<span>GWT</span><span>Create</span>") .animate($$("y:+200px,x:+50px,color:yellow"),3000) .on("click","span",new Function(){ publicvoidf(){ console.log($(this).text()); } }); } }); RootPanel.get().add(widget); 18/35
  • 19. Decouple your widgets Find any widget of a specific java class. By default it looks for widgets attached to the RootPanel Enclose your search using especific selectors like '.gwt-Label' or specific contexts. Then you can use those widgets as usual in your GWT application //YougetalistwithallMyBreadCrumbmatchingtheselector List<MyBreadCrumb>list=$(".gwt-Label").widgets(MyBreadCrumb.class); MyBreadCrumbcrumbs=list.get(0); crumbs.addCrumb("Rocks"); 19/35
  • 20. GWT Ajax never was simpler. Just one line of code vs dozen of lines using RequestBuilder Reusable responses via Promises Advanced features Upload/Download progress, FormData, CORS Usable in the JVM //ConfigurableviaPropertiessyntax Ajax.get("/my-rest-service/items",$$("customer:whatever")); Ajax.post("/my-rest-service/save",$$("id:foo,description:bar")); Ajax.loadScript("/my-cdn-host/3party.js"); Ajax.importHtml("/bower_components/3party-web-component.html"); //OrviatheSettingsinterface Ajax.ajax(Ajax.createSettings() .setUrl("/my-3party-site/service") .setWithCredentials(true) .setData(GQ.create().set("parameter1","value"))) .fail(new Function(){ publicvoidf(){ console.log("Thecallshouldfailbecauseurl'sareinvalid"); } }); 20/35
  • 21. Make your async code more declarative and simpler Avoid nesting callbacks Chain promises methods to add callbacks Reuse resolved promises to avoid requesting twice the same service resolved status is maintained for ever Pipe your callbacks //Wecanreusetheloginpromiseanytime PromiseloginDone=Ajax.post("/my-login-service",$$("credentials:whatever")); GQuery.when(loginDone) .then(Ajax.post("/my-rest-service",$$().set("param","value"))) .done(new Function(){ publicObjectf(Object...args){ returnsuper.f(args); } }).fail(new Function(){ publicvoidf(){ console.log("LoginError"); } }); 21/35
  • 22. JSNI sucks, how does gQuery help? Export java functions to JS objects This will be covered by JsInterop But sometimes you will be interested on simply export one method Execute external functions Automatically boxes and un-boxes parameters and return values Wrap any JS object with JsonBuilders It supports functions Load external libraries via JsniBundle JsUtils.export(window,"foo",new Function(){ publicObjectf(Object...args){ returnargs[0]; } }); Stringresponse=JsUtils.jsni(window,"foo","ByeByeJSNI"); console.log(response); 22/35
  • 23. Simplifying deferred binding gQuery Browser flags are set in compilation time. They return true or false, making the compiler get rid of other borwsers code Not necessity of create classes nor deal with module files if(browser.webkit){ console.log("WebKit"); }elseif(browser.ie6){ //Thiscodewillneverbeinchromepermutation Window.alert("IE6doesnothaveconsole"); }else{ //Thiscodewillneverbeinchromepermutation console.log("NotwebkitnorIE.Maybemozilla?"+browser.mozilla); } 23/35
  • 25. How to extend gQuery? Plugins add new methods to GQuery objects It's easy to call new methods via the as(Plugin) method Plugins also could modify certain behaviors of gQuery: support for new selectors synthetic events new css properties ... publicstaticclassCss3AnimationsextendsGQuery{ //Wejustneedaconstructor,andareferencetothenewregisteredplugin protectedCss3Animations(GQuerygq){ super(gq); } publicstaticfinalClass<Css3Animations>Css3Animations=GQuery .registerPlugin(Css3Animations.class,new Plugin<Css3Animations>(){ publicCss3Animationsinit(GQuerygq){ returnnew Css3Animations(gq); } }); //Wecanaddnewmethodsoroverrideexistingones publicCss3Animationscss3Animate(Propertiesproperties){ super.animate(properties); returnthis; } } $(".ball").as(Css3Animations.Css3Animations).animate($$("rotateX:180deg,rotateY:180deg" 25/35
  • 26. How to port a jQuery plugin to gQuery Gesture Plugin Differences Take original JS code Create JsBuider interfaces so as syntax is similar to JS Set appropriate java types to JS variables Gesture Plugin Source Gighub Gesture Plugin Demo $(".current.jCode").as(Gesture.Gesture).on("taptwo",new Function(){ publicvoidf(){ console.log("DoubleTap"); } }); 26/35
  • 27. What is the future of gQuery Type safe functions and promises Full support for java 8 lambdas Mobile friendly Integration with JsInterop GQueryg=$(".ball"); g.each(new IsElementFunction(){ publicvoidrun(Elementelm){ $(elm).animate("scale:1.2"); } }); g.on("tapone",new IsEventFunction(){ publicBooleancall(Eventevt){ return$(evt).animate($$("rotateX:90deg")).animate($$("rotateX:0deg")).FALSE; } }); //PredefinedreturntypesinthegQuerychain g.on("taptwo",(e)->$(e).animate($$("x:+=50")).TRUE); //Gettheresultofmultiplecallbacks $.when(()->"aaa",()->"bbb",Ajax.get("/lambdas.html")) .done((Object[]s)->console.log(s[0],s[1],s[3])) .fail((s)->console.log("Fail")); 27/35
  • 28. Show me more cool code ... 28/35
  • 29. Example: Material Design Hierarchical Timing. boxes.each(new Function(){ intscale=boxes.isVisible()?0:1; publicvoidf(Elemente){ GQueryg=$(this); intdelay=(int)(g.offset().left+g.offset().top); g.animate("duration:200,delay:"+delay+",scale:"+scale); } }); 29/35
  • 30. Example: Material Design Ripple Effect. //Createtherippleelementtobeanimated finalGQueryripple=$("<div>").as(Transitions.Transitions).css( $$("position:absolute,width:40px,height:40px,background:white,border-radius:50%" //Addrippleeffectstocertainelementswhentheyaretapped $(".jCode,.button,h1").on("tap.ripple",new Function(){ publicbooleanf(Evente){ GQuerytarget=$(this).css($$("overflow:hidden")).append(ripple); intx=e.getClientX()-20-target.offset().left; inty=e.getClientY()-20-target.offset().top; intf=Math.max(target.width(),target.height())/40*3; ripple.css($$("opacity:0.8,scale:0.5")).css("left",x+"px").css("top",y+"px"); ripple.animate($$("opacity:0,scale:"+f),new Function(){ publicvoidf(){ ripple.detach(); } }); returnfalse; } }); 30/35
  • 31. Example: Wrapping Web Components with gQuery Use bower to install components in the public folder bower install Polymer/paper-slider Use Ajax utility methods to load polyfills and import templates Web Components can be created and manipulated as any other element. We can change its properties or bind events. Ajax.loadScript("bower_components/webcomponentsjs/webcomponents.js"); Ajax.importHtml("bower_components/paper-slider/paper-slider.html"); GQueryslider=$("<paper-slider/>").appendTo($("#sliders-container")); slider.prop("value",67); slider.on("change",(e)->{ console.log($(e).prop("value")); returntrue; }); $("#sliders-container").append("<paper-slidervalue=183max=255editable>"); 31/35
  • 32. Example: Binding Attributes of Web Components. JsonBuilder can wrap any JavaScript element Light Weight wrapper Type safe Chain setters publicinterfacePaperSliderextendsJsonBuilder{ //get/setprefixesareoptional intgetValue(); //Chainingsettersisoptional PaperSlidersetValue(intvalue); PaperSlidermin(intvalue); PaperSlidermax(intvalue); PaperSliderstep(intvalue); PaperSlidersnaps(booleanvalue); PaperSliderpin(booleanvalue); } //Waituntilthepolyfillandthewebcomponenthasbeenloaded GQuery.when( Ajax.loadScript("bower_components/webcomponentsjs/webcomponents.js"), Ajax.importHtml("bower_components/paper-slider/paper-slider.html") ).done(new Function(){ publicvoidf(){ //CreateandappendtheelementasusualingQuery GQueryg=$("<paper-slider>").appendTo($("#slider-container")); //WrapthenativeelementinaPOJO PaperSliderslider=GQ.create(PaperSlider.class).load(g); //Useitasajavaobject slider.setValue(300).max(400).step(50).snaps(true).pin(true); } }); 32/35
  • 33. Example: Uploading files with progress bar. finalGQueryprogress=$("<div>").css($$("height:12px,width:0%,background:#75bff4,position:absolu finalGQueryfileUpload=$("<inputtype='file'accept='image/*'>").appendTo(document).hide fileUpload.on("change",new Function(){ publicbooleanf(Evente){ finalJsArray<JavaScriptObject>files=$(e).prop("files"); JavaScriptObjectformData=JsUtils.jsni("eval","newFormData()"); for(inti=0,l=files.length();i<l;i++){ JsUtils.jsni(formData,"append","file-"+i,files.get(i)); } Ajax.ajax(Ajax.createSettings() .setUrl(uploadUrl).setData(formData).setWithCredentials(true)) .progress(new Function(){ publicvoidf(){ progress.animate("width:"+arguments(2)+"%",1000); } }).always(new Function(){ publicvoidf(){ progress.remove(); } }).done(new Function(){ publicvoidf(){ uploadImg.attr("src",uploadUrl+"&show=file-0-0"); } }); returntrue; } }).trigger("click"); 33/35
  • 35. Questions and Answers Rate this talk: http://gwtcreate.com/agenda when(()->"Talk") .then((o)->"Questions") .and((o)->"Answers") .done((o)->console.log("Thanks")); 35/35