I am building a GWT app that uses Web SQL Local Storage ( http://dev.w3.org/html5/webdatabase/ ). The problem is that the Web SQL API uses callback functions as arguments.
Is it possible to pass "Java" callbacks to JSNI?
Yes, it does:
private static native void doThingWithCallback() /*-{
var self = this;
var callbackFn = $entry(function(val) {
[email protected](Ljava/lang/String;)(val);
});
$wnd.someApiThatTakesACallback(callbackFn);
}-*/;
Two things to remember:
$entry() reminds GWT to keep track of the code when using the debugger.var self = this keeps the reference to this inside the function -- otherwise this will be the function itself...If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With