On Friday, July 13, 2018 at 2:57:10 PM UTC+2, Kirill Prazdnikov wrote:
>
> Hi, I've heard that mysterious J2CL does not support JSNI, good. 
>
> But how then the Float32Array is implemented ? 
> As far as I know, there is no JSIndexer-like (hello TeaVM) annotation in 
> JsInterop ? 
>
> Currently everyone is using JSNI llike 
>
>   public static native float getF(Float32Array data, int i) /*-{
>>       return data[i];
>>   }-*/;
>
>
> Thanks
>

Don't worry, there's an alternative to JSNI. Its usage is meant to be much 
smaller and exceptional than JSNI though.

Basically, you declare a method 'native' and give it a known name using 
JsInterop (i.e. annotate it with @JsMethod), and then in a JS file you can 
implement it, in "standard Closure way" (the class has the same name in JS 
as in Java, so you assign a function to MyClass.prototype.getF).
That said, for this specific case, you'd probably better extend 
JsArrayLike<Double> from jsinterop-base (this is what 
elemental2.core.Float32Array does; knowing that java.lang.Double is 
interchangeable with double as a representation of JS Number type, without 
any overhead); or implement the method by casting to JsArrayLike<Double>:
public static float getF(Float32Array data, int i) {
  return Js.asArrayLike(this).getAnyAt(i).asFloat();
}

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to