I'm also interested in Cristian's second question about using callback functions. Is this supposed to "just work" with the current master or is Cristian's EventListenerFactory workaround the best bet for now?
-- Cheers,
James
On Monday, August 11, 2014 7:17:32 PM UTC+1, Cristian Rinaldi wrote:
On Monday, August 11, 2014 7:17:32 PM UTC+1, Cristian Rinaldi wrote:
I was playing with JsInterop and perform several examplesDataTables Plugin of JQuery (import)Polymer (Path Observer, Object Observer), etc...Here my exmaples:But I 2 question about JsInterop:The first question with JsInterop is about the import methodology, when I define a interface that maps with a JS core Element, by example: Object or JSON, I not sure the best form for maps the static method of the Object, by example Object.observe(...), or JSON.stringify().My understanding of JsInterop is that one defines an interface, which is implemented by the compiler.And the allocation for now is through a factory in JSNI, talking to correlate Object for example, for Polymer ObjectObserver:
public static native <T extends JsObject> ObjectObserver<T> createObjectObserver(T obj)/*-{
return new $wnd.ObjectObserver(obj);
}-*/;
But the asignations is a instance of Object, and the observe() method is a static method.How to is the best form of map this case?The second question is about function callback passed to the Javascript method
button.addEventListener("click" , function(event){
console.log(event);
});The way I found to the compiler to generate things correctly was:
button.addEventListener("click" , EventListenerFactory.createEventListener (new EventListener<JsObject>() {
@Override
public void onEvent(JsObject event) {
//TODO
}
}));where:
public class EventListenerFactory {
public static native gwt_sample.EventListener createEventListener(EventListener listener)/*-{
return function(evt){
listener.onEvent(evt);
}
}-*/;
}and:
@JsType
public interface EventListener<E extends JsObject> {
void onEvent(E event);
}
Thanks!!
El lunes, 11 de agosto de 2014 09:03:00 UTC-3, salk31 escribió:Thanks. I have great hopes for this stuff ;)
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" 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 http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment