Thursday, May 12, 2016

Re: jsinterop: converting a jre collection to a jsArray

Thomas thanks,

Wow I did this and it works. But it is crazy. Cr is for crazy. Kudos to jsinterop guys though.

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "[]")
public interface CrJsArray<T> {

    public void push(T value);

    @JsProperty
    public int getLength();
}

I tried your suggestion to cast and __also works__ (eclipse complains about but with (JavaScriptObject) (Object) my_native_object) it works and it is definitely better.

Questions
1) Is JavaScriptObject scheduled for deprecation?
2) Should a native type be able to extend JavascriptObject. Because right now (2.8pre1) fails at run time. That would make casting a bit saner. Should I report it somewhere?

I tried to look for the reference you gave but I didn't find it. Wrong keywords maybe...


On Thu, May 12, 2016 at 12:20 PM, Thomas Broyer <t.broyer@gmail.com> wrote:
That question came up already in the forum or in GWT-Contrib (try to search the archive), and I seem to recall that Goktug said you could cast @JsType(isNative=true) objects to/from JavaScriptObject, so you could use JsArray (and JsonUtils.safeEval). I think you can also cast to/from an array of @JsType(isNative=true), so if you don't need to alter the size of the JS array you can then use the bracket operators on a Java array (and cast from/to a JavaScriptObject).
This is only out of memory, please double check from the forum archives.


On Thursday, May 12, 2016 at 10:47:51 AM UTC+2, Vassilis Virvilis wrote:
Hi again,

I am trying to convert a jre collection or build a jsArray with a isNative=true type.

Unfortunately this is not possible because JsArray requires JavascriptObject which is invcompatible (complie time error) with native classes.

Any ideas?

I looked on deep dive jsinterop from Ray Cromwell and it says that there is not a clean way for jsinterop1 to align collections. Ok I get that - but there must be a way even if not the nicest/cleanest one.

Otherwise looks like I have to create my own @jsinteroped MyJsArray which looks wrong.

--
Vassilis Virvilis

--
You received this message because you are subscribed to the Google Groups "GWT Users" 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 https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.



--
Vassilis Virvilis

--
You received this message because you are subscribed to the Google Groups "GWT Users" 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 https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment