Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Runtime Evaluation
import gwtquery.client.GwtQuery;
import static gwtquery.client.GwtQuery.$;
• On Safari 3.1
• document.querySelectorAll(selector)
• On Firefox, Opera, older Safari
• Lots of Regexp parsing to compute xpathExpression
• document.evaluate(xpathExpression)
• On IE < 8 and others, a bunch of Regexp and DOM calls
• Note: Each browser gets separately compiled JS
Digression: Generators
Compile-time parsing
selector.allFirstMenuItems().html(“hello”);
GwtQuery Example
Compile-time parsing
ul > li:first-child
becomes
document.evaluate(“ul/li[position() = 1]”)
GwtQuery Example
• jQuery 1.2.3
• ~3400 lines of Javascript
• 98kb unprocessed source
• 15kb obfuscated and gzipped
• GwtQuery
• ~3400 lines of Java
• 116kb on disk
• How big is it compiled?
• 15kb or larger?
• How about 7kb, a 50% reduction?
• 3kb sounds about right!
• 712 bytes is the answer!
• Smaller than single packet, HTTP headers
Caveats and Objections
• Trivial example
• More reasonable example would exercise larger part of API
• and reduce amount of pruned code
• Example shows how aggressive GWT optimizer is
• past GWT critics have used Hello World examples to
demonstrate purported “bloat”
Demo: Progressively Enhancing <UL> into
PowerPoint-like slide transitions
Sample Code
<div class="slide transition-fade">
Slide 1
<ul class="transition-fade">
<li>Point One</li>
<li>Point Two</li>
<li>Point Three</li>
</ul>
</div>
<div class="slide transition-fade">
Slide 2
<ul class="transition-appear">
<li>Slide 2 Point One</li>
<li>Slide 2 Point Two</li>
<li>Slide 3 Point Three</li>
</ul>
</div>
GwtQuery code
XPath Version
implements
LocationServiceClient Android Bootstrap
Synchronous RPC
public interface AndroidNativeInterface {}
@ANIBinding("locationService")
@ImplementedBy("LocationServiceImpl")
public interface LocationService
extends AndroidNativeInterface {
String getLocation();
}
Example: Android Native Interface
To use
@ANIBinding
Example: Linker Generated Manifest
Needed by Android
<manifest xmlns:android="
http://schemas.android.com/apk/res/android"
package="syndroid.demo.SyndroidDemo"><uses-permission
android:name="android.permission.ACCESS_LOCATION"/><uses-
permission android:name="android.permission.ACCESS_GPS"/><uses-
permission
android:name="android.permission.ACCESS_ASSISTED_GPS"/>
<application> <activity android:name="BootstrapActivity"
android:label="SyndroidDemo"> <intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category
android:name="android.intent.category.LAUNCHER"/>
</intent-filter> </activity> </application></manifest>
Example: Linker Generated Build Script
• Define ActionScriptNativeInterface
• Place all “Flash” java code in .flash package
– Use generator to copy it to output as a resource
• Use Generator to create JSNI stubs to invoke
Flash methods
• But how do we turn Java code into SWF for
the server side?
ActionScript Native Interface
ActionScriptNativeInterface
Written by Developer
extends package foo.flash;
implements
DrawServiceClient Flash Bootstrap
• GwtQuery available at
– http://gwtquery.com
• Chronoscope available
– http://timepedia.org
• For in-depth articles/code, see blog at:
– http://timepedia.blogspot.com
• Upcoming articles on Syndroid, and
ActionScriptNativeInterface