1

I am working with GWT 2.8, and I am working on a wrapper for a javascript library.

One of the properties of a javascript class I am trying to wrap is a function. I would like the wrapper to work as closely as possible to the native javascript. How do I go about wrapping a JsProperty that is a javascript function?

Details: The javascript class has a property that is a function that is called when a specific event is triggered. I would like to be able to write a labmda function in Java, and assign it to this property, which would then run in javascript.

asked Aug 15, 2017 at 18:27
1

1 Answer 1

3

As Adam said (and explained in more detail in the other post), you can expose a @JsProperty with a @JsFunction type.

@JsType(isNative=true) public class Foo {
 @JsFunction public static interface BarFn {
 Object invoke(Object... args);
 }
 @JsProperty public BarFn bar;
}

My recommendation to learn JsInterop is to explore other projects like: OpenLayers JsInterop wrapper, Elemental2 source code, or explore github. Elemental2 has the whole browser API so there are plety of examples, it is a really good place to find examples. JsInterop documentation here.

answered Aug 16, 2017 at 16:07
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.