Saturday, May 14, 2016

Re: Importing javascript functions to GWT using JSInteropr?


Is it possible to import the API of a javascript library to GWT using JsInterop?

E.g, stripe.js has methods such as: Stripe.card.validateCardNumber(number) which takes a string, and takes a boolean.

I have a feeling that it should be possible to import this function using @JsMethod perhaps, but I'm not sure of the exact syntax. The specs doc is a little bit lacking in examples.

I'm using 2.8.0-beta1 

The doc is lacking examples? IMHO its pretty descriptive for your use case. Using the JsInterop annotations you can import any JS library.

 

Question 2: What if a javascript API performs some async function, and requires a callback to be passed in which contains the result of the operation. Is that possible to handle using JsInterop?

You can use any interface / class as callback as long as this interface/class has exactly a single abstract method (SAM). If you have that you can mark that interface / class using @JsFunction and JsInterop will convert it to a JS function that can be passed to JS code as a callback.


-- 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