@Kay-Uwe Janssen
I am doing support IndexedDB with JsInterop to do some tests, and also I
have to assign a function:
interface IDBRequest : EventTarget { ...* attribute EventHandler
onsuccess
<https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBRequest-onsuccess>;*
attribute EventHandler onerror
<https://dvcs.w3.org/hg/IndexedDB/raw-file/tip/Overview.html#widl-IDBRequest-onerror>;
};
Use the request in JS:
request.onsuccess = function() { ... };
This can be translated as follows:
@JsType
public interface IDBRequest {
@JsProperty
public void onsuccess(Function fn);
}
@JsType
public interface IDBOpenDBRequest extends IDBRequest{}
@JsType
public interface IDBFactory {
public IDBOpenDBRequest open(String db, int version);
}
@JsType
public interface IDBEnvironment {
@JsProperty
IDBFactory indexedDB();
}
@JsType(prototype = "window")
public interface Window extends IDBEnvironment{}
And use:
IDBOpenDBRequest req = Window.Static.get().indexedDB().open("db", 1);
req.onsuccess(Function.Static.newInstance(new Function<Object, Void>() {
@Override
public Void f(Object changed) {
console.log(changed);
return null;
}
}));
The code here:
- https://github.com/workingflows/gwt-jscore.git
- https://github.com/workingflows/gwt-jquery.git
- https://github.com/workingflows/gwt-playground.git
Cheers!!
El jueves, 6 de noviembre de 2014 04:46:08 UTC-3, Kay-Uwe Janssen escribió:
>
> @Cristian Rinaldi unfortunately this does not work how i need it. it still
> assignes the object and not the javascript function.
>
> i think i have to wait for 2.8 to get it working. but thanks anyway :-)
>
> Am Mittwoch, 5. November 2014 08:28:21 UTC+1 schrieb Kay-Uwe Janssen:
>>
>> As i had no luck on Google+ yet, i'll try it here.
>>
>> First the G+ Post:
>> https://plus.google.com/116136390679208063122/posts/52kcbwwngWo
>>
>>
>> Well I just started to work on a ChromeCast Receiver built with GWT. As
>> the Receiver API is in JS i wanted to try JSInterop over JSNI but had some
>> struggle.
>>
>> The ChromeCast Api has some properties that can be set with a function to
>> act as a callback. eg for onReady.
>>
>> castReceiverManager.onReady = function(event) {
>> // do stuff
>> };
>>
>> Now my question is: How can i do this with JsInterop or is it not yet
>> possible?
>>
>> as mentioned in
>> https://docs.google.com/document/d/1tir74SB-ZWrs-gQ8w-lOEV3oMY6u6lF2MmNivDEihZ4
>>
>> below "Single Abstract Method Handling" i tried something like this
>>
>> @JsType
>> public interface Receiver {
>> @JsProperty
>> void onReady(Runnable onReady);
>> }
>>
>> when trying to execute the method with this snipped i get "Exception
>> caught: (TypeError) : object is not a function"
>>
>> private native void test(Receiver receiver)/*-{
>> receiver.onReady();
>> }-*/;
>>
>>
>> to see whats the value of onReady i did console.log(receiver) and got
>> this: (where onReady is set the way above and onSenderConnected has been
>> set the JS way inside an JSNI method.
>>
>> onReady: JsTest$1_1_g$
>> onSenderConnected: function (event_0_g$)
>>
>>
>> is there a way to achieve this yet or do i have to wait for 2.8/3.0?
>>
>> i tried to dig into the gwt code to see if there is a way to add
>> something to support this but unfortunately the gwt code for js processing
>> is a bit out of my scope.
>>
>>
>> some possible solutions would be either
>> interface JsFunction {
>> <T> T call(Object... args);
>> }
>> or
>> interface MyOnReadyCallback {
>> @JsFunction
>> MyReturnType anyName(String arg1, boolean arg2, SomeOtherType arg3);
>> }
>>
>> and let the "Single Abstract Method Handling" find the method and add it.
>>
>>
>> Thanks! :)
>>
>
--
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-web-toolkit-contributors/b78d26e7-3626-4fff-ab7f-fa987ccca0d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.