THIS PRESENTATION IS ONLINE! lteconsulting.fr/angular2boot-gwtcon2016 works on your phone too ;) Demo code available at 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
WHY DO THAT? I want to bene t from the best UI coding paradigms (Data binding, DI, … ). I want strong typing and powerful IDE tools. I want to be more productive. I want to be in phase with the future. (I may want to progressively migrate an existing app)
GWT 2.8 CORE Java 8 (strong typing, lambdas, streams, … ) JsInterop (easy integration with JS) SuperDevMode (incremental fast compile on reload) Optimized compilation for production (js size, ef ciency)
COMPONENTS Most basic building block of the application. A component is a class with: a view (an HTML template), and a model (data and methods). Interaction between view and model through data binding.
COMPONENTS Each component is responsible for a part of the DOM tree. Components also form a tree. A bit like the GWT Widgets… Components interacts with each other through cleanly de ned ways.
DEPENDENCY INJECTION Sharing services between components. Lifecycle and dependencies are managed by Angular. Each component has a Dependency Injector. Those also form a tree.
DATA BINDING Angular uses Zone.js to track changes. Zones == asynchronous TLS. Preserve an execution context across asynchronous calls. (done by patching most of the browsers async functions)
GWT IN ANGULAR2BOOT Only uses the compiler, JsInterop used a lot, No widgets, no User module (unless you want to mix legacy GWT and Angular). Because that’s how future will look like.
JSR 269 - PLUGGABLE ANNOTATION PROCESSING API Shown here last year! Standard API for code generation in Java. (Used to generate the boiler plate code Angular requires.) Registered annotation processors receive the program’s AST and can then generate les (sources, byte-code or resources) which are part of the compilation. Integrated with the Java compiler.
GOOD POINTS Generated code is visible and debuggable, You can reference the generated code in your code. No overhead at runtime. (Does not depend on byte code: GWT compatible)
FEEDING ANGULAR WITH METADATAS Angular requires metadata on components (DI, routing, inputs/ouputs, … ) and uses ES7/Typescript decorators (ex @Component()) for this purpose. Those decorators alter component’s constructor at runtime so that less boilerplate code is required.
HOW? JSR-269 is used to generate RTTI, Use Angular JS API through JsInterop to provide the RTTI. Fetch Java class compiled JS constructor at runtime, Patch it with Angular required metadata, Provide the patched constructor function to Angular.
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).
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 (for dev mode only).
LEGACY GWT WIDGETS INTEGRATION Works both ways : GWT widgets inside an Angular2Boot application: WidgetAdapterPanel. Angular 2 components in a legacy GWT application: AngularComponentContainerWidget.
UNIT TESTS Dif cult to use the GWTTestCase facility HTMLUnit does not support Angular 2 runtime (not ES6 compatible) More, GWT uses Jetty as a testing backend but we want to be able to use any backend (eg. SpringBoot). No real solution yet…
MODULE LOADING Not easy! Best is maybe to wait for GWT3 (J2Cl) which will be more ES7 module friendly. Will allow more AOT compilation optimizations (Angular AOT compiler may be able to work on the generated code). Better integration with JS build and packaging tools.
JAVASCRIPT AND JAVA COMMMUNITIES NEED TO EXCHANGE! WebPack inspired by GWT’s code splitting, Problems solved by Java since 20 years should inspire JS! Dynamism of the JS ecosystem should inpire Java!
USE CASES 100% Java applications (small or big), Service implementations in Java (strongly typed Web service interfacing), JS, Typescript and Java integration, Would t well with JBoss Forge and JHipster…
HOW COOL IS THAT? Tested on few projects, was very impressive! Work ow is really comfortable. Dead simple bootstrapping (only one maven dep, simpler than Angular 2 itself!). GWT compilation without User module (Widgets) is dead fast. Gives GWT a second youth! (only uses the core). Optimizations done by GWT are still very powerful: fast application, small download.