Monday, October 16, 2017

Re: Is there a good tutorial with examples for JSInterop available somewhere ?

The most in-depth documentation is already linked at the very bottom of the corresponding gwtproject.org page:

https://docs.google.com/document/d/10fmlEYIHcyead_4R1S5wKGs1t2I7Fnp_PaNaa7XTEk0/edit#heading=h.828haudjx0kl

In addition there is a document which talks about union types in elemental2 which can be helpful as well if you have to deal with union types: 

https://docs.google.com/document/d/14mQeAGQ9M_5uTTUbzRQzCYETA887dTO-xFLtQhgUXXk/edit


In general if you want to consume existing JS API then just model that API using @JsType(isNative = true, ...) annotated classes and for callbacks use @JsFunction annotated interfaces. Your small example could be something like:

@JsType(isNative = true, ....) // TODO: namespace, name
class Items {
 
native void on(String event, ItemsEventCallback callback);
}

@JsFunction
@FunctionalInterface
interface ItemsEventCallback {
 
void onEvent(Object event, Object properties); // TODO: parameter types should probably of a specific type but I don't know the JS library so have used Object here.
}


-- J.

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment