Beruflich Dokumente
Kultur Dokumente
github.com/ltearno/tour-of-heroes
github.com/ltearno/angular2boot-demos
ANGULAR 2 BOOT?
A new RIA paradigm for Java : programming Angular 2 with
Java 8.
The coolest Java 8 RIA framework in the place ;)
lteconsulting.fr/angular2boot
A MORE TECHNICAL TITLE
Integrating Angular 2 and GWT 2.8:
problems and solutions
WHY?
Angular 2 natively supports Typescript and Javascript.
Angular 2 for Dart is maintained by the Dart team.
Nevertheless Java has all the required features.
a view (template),
and a model (data and methods).
JsInterop,
Java 8 language,
Time to drop Widgets and old stuff!
GWT 3 (AKA J2CL)
not released yet
Lightweight,
More unopiniated (can be integrated anywhere),
Drops a lot of functionalities done now by standard tools.
GWT FUNDAMENTALS
THE COMPILER
Preserves Java semantic,
Still does a bunch of optimisations (pruning, static
analysis..),
Mostly ouputs modern Javascript, optimizable with
Closure Compiler.
JSINTEROP
A very easy way to integrate Javascript and Java code.
A two-way road (JSJava, JavaJS)
JSINTEROP
To use JS code from Java, you just have to describe the JS
type :
@JsType(isNative=true)
publicclassXMLHttpRequest
{
@JsMethod
publicnativevoidopen(Stringmethod,Stringurl)
@JsMethod
publicnativevoidsend(Objectdata)
//...
}
JSINTEROP
Then use the class as a normal Java class
XMLHttpRequestrequest=newXMLHttpRequest()
request.open("GET","service.json")
request.setOnreadystatechange(event>{
...
}
request.send(...)
JSINTEROP
And the other way around (exporting Java to JS)
packagefr.lteconsulting
@JsType
publicclassRobot
{
@JsProperty
privatebooleanwifiOn
@JsConstructor
publicRobot(DataServicedataService){...}
@JsMethod
protectedvoidmove(){...}
}
JSINTEROP
In Javascript :
letrobot=newfr.lteconsulting.Robot(dataService)
robot.wifiOn=true
robot.move()
mvncleaninstall
javajartarget/YOUR_ARTIFACT_ID.jar
COMPILE ON RELOAD
#Backend
mvnspringboot:run
#Frontend
mvngwt:runcodeserver
PRODUCTION CODE
mvncleaninstall
HeroDetailComponent(privateHeroServiceheroService){}
ngOnInit(){...}
//...
}
JAVA EQUIVALENT
@Component(selector="myherodetail",
templateUrl="herodetail.component.html",
styleUrls="herodetail.component.css")
@JsType
publicclassHeroDetailComponentimplementsOnInit
{
@InputpublicHerohero=null
@OutputpublicEventEmitter<Hero>updated=newEventEmitter<>()
privateHeroServiceheroService
publicHeroDetailComponent(HeroServiceheroService)
{
this.heroService=heroService
}
@Override
publicvoidngOnInit(){...}
THE INSTANCEOF PROBLEM
Angular checks at runtime that components are valid.
With SuperDevMode, code is loaded in an external frame
thus breaking instanceof operator.
Few places needed to be patched
MODULE LOADING PROBLEM
GWT is not SystemJS (ES7 modules) friendly.
Need to generate a bundle with all Angular inside (you can
choose/build your bundle depending on what you need).
BUILDING ANGULAR
Angular 2 requires a strict environment to be built.
Docker to the rescue!
From RC6 to nal: 1 hour of work!
LEGACY GWT WIDGETS INTEGRATION
In fact it worked out of the box, no problem, cool!
EMULATING ES6 GET AND SET OPERATORS
Java does not provide this language facility
So we use JSR-269 to generate trampoline functions,
triggered by @PropertyGetter and @Input annotations.
TESTING
Unit tests,
Integration tests.
UNIT TESTS
No production-ready way to do that with Angular yet,
Dif cult to use the GWTTestCase facility (need to
bootstrap Angular in the testing environment which runs
under HTMLUnit which is not ready for ES6. More, GWT
uses Jetty as a testing backend but we want to be able to
use any backend - Angular2Boot uses SpringBoot).