>
>
>>    1. @JsFunction exported to JS doesn't have apply() and call()
>>     operations. Apply() is used by JQuery (2.1.3) to call callbacks, so 
>>    basically it wasn't possible to add handlers using JQuery. See other 
>> thread 
>>    on this: 
>>    https://groups.google.com/forum/#!topic/google-web-toolkit/PHtfLTSAJDM
>>     
>>
>> Pretty interesting how to model that JQuery callback with JsInterop. 
> Basically when you do $("p").click(handler) then JQuery sets "this" for the 
> handler to the element the event occurred on so you can do 
>
> $("p").click(function() {
>    $(this).slideUp(); // slides the clicked p element up
> });
>
> I think you can't really do that with just JsInterop. I think your Java 
> callback must be JQueryCallback.exec(Element elem, Event e) and you have to 
> use JSNI to create a pure JS function that passes "this" as "elem" to the 
> JQueryCallback.
>


This is definitely problematic. I didn't give it too much though, but I 
think it would be great if we could opt-in to get the *this* from 
JavaScript. Something like this: 

@JsFunction
public interface HandlerWithThis {
   public void onEvent(*@JsThis* Element target, Event e);
}

If you need the JavaScript *this,* then you just add it as parameter to 
method with @JsThis annotation. As currently @JsFunction is not a 
JavaScript function, but an object that pretend the function, it should be 
possible to implement apply() and call() in such a way, that it passes this 
if there is a @JsThis parameter in the method signature. In case you don't 
need *this*, you just don't specify such parameter; in such case the method 
signature would be void onEvent(Event e). This would be much nicer then 
telling, you need to go to JSNI to do that. 

Do you think it could be done like this?

Thanks,
Marcin


-- 
You received this message because you are subscribed to the Google Groups "GWT 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/97624985-35bf-48d6-b187-76181d9b8672%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to