cincheo / jsweet

A Java to JavaScript transpiler.
http://www.jsweet.org
Other
1.45k stars 159 forks source link

support webcomponent ? #224

Open zzj1213 opened 7 years ago

zzj1213 commented 7 years ago

The jsweet.dom.Element support the web components like custom element, shadow dom ? Search the doc, could not find the methods like createdCallback on jsweet.dom.Element.

renaudpawlak commented 7 years ago

That's most probably because the methods your are talking about come from mixins. So they are not defined in the jsweet.dom.Element interface itself, but they are defined somewhere else and injected in jsweet.dom.Element. In the worst case, you can always access methods reflectively using the $get accessor (as explained in other posts and in the doc).

If you want us to support a specific API, the best is to find the TypeScript definition file and we can try to apply the API translator (candy generator) tool on it to get the Java API.

zzj1213 commented 7 years ago

Thanks for the reply.

Can I just edit the Element.java and add the missing method to it ?

lgrignon commented 7 years ago

@zzj1213 sorry we didn't answer for this long. Actually, the webcomponents topic is a little bit tricky because specifications are mainly still WIP, according to W3C & MDN: https://www.w3.org/standards/techs/components#w3c_all https://developer.mozilla.org/fr/docs/Web/Web_Components

Nevertheless, you should be able to use the webcomponents polyfill or some framework built over it. I created an example around Polymer using JSweet: https://github.com/lgrignon/jsweet-cordova-polymer-example

Anyway, as being said by @renaudpawlak, in JSweet, you can access everything which is accessible in JavaScript using the methods:

jsweet.lang.Object /* or def.js.Object with JSweet 2 */ myObject = ...;
Runnable oldCreatedCallback = myObject.$get("createdCallback"); // $get
Runnable newCreatedCallback = () -> { console.log("yipi - it's created"); };
myObject.$set("createdCallback", newCreatedCallback ); // $set