lofidewanto / webcomponents-gwt-simple-examples

Web Components Simple Example with GWT
Apache License 2.0
5 stars 2 forks source link

webcomponents-gwt-simple-examples

Web Components Simple Examples with GWT and J2CL

Contents


General Information ECMAScript ES5 and ES6

Transpilers GWT and J2CL

Web Components (WC)

Web Components Summary

The "Web Component" spec is actually 4ish specs, though one didn't pan out and is deprecated and already removed from all browsers

Technically these features can be used individually, and you you can just pick and choose what you want, but as best as i can tell you really do need them all together.

Example 1: my-button-gwt-example

Running Example 1

To run the examples: just go to the Maven project directory and run

mvn gwt:generate-module gwt:devmode

Explanation Example 1

This example shows how to build Web Component completely in Java / GWT / JsInterop. Afterwards you can use it by just adding the component <my-button></my-button> in the index.html

Comments from Colin: See: https://gitter.im/gwtproject/gwt

Building Web Component (WC): comments from Colin:

Example 2: my-button-j2cl-es5-example

Running Example 2

To run the examples: just go to the Maven project directory and run

mvn j2cl:build

and open the index.html in following directory (without server, just double click the file)

target/my-button-j2cl-es5-example-1.0.0-SNAPSHOT/index.html

Explanation Example 2

This example is just similar to Example 1 but we use J2CL to transpile to ES5. It works well and show the same result as Example 1, the main difference is the transpiler we use.

Example 3: my-button-j2cl-es6-example

Running Example 2

To run the examples: just go to the Maven project directory and run

mvn j2cl:build

and open the index.html in following directory (without server, just double click the file)

target/my-button-j2cl-es6-example-1.0.0-SNAPSHOT/index.html

Explanation Example 2

This example uses J2CL to transpile to ES6 JavaScript. With this in mind we can remove all the workaround code to create a Web Component. If you see this code: MyButton.java it looks now very clean and very similar to the JavaScript WC code here: https://www.robinwieruch.de/web-components-tutorial.

How to Check for the Result: ES5 or ES6?

Take a look at the generated JavaScript. if you see the class keyword, or super(), or constructor(), you know it is ES6.

Example 4: use-my-button-gwt-example

This example shows how to use already created Web Components in your Java / GWT project. In this case you have at the moment 2 possibilities in GWT:

Tip to consume Web Components from GWT: comments from Thomas:

... Todo ...