Re: [gwt-contrib] Digest for google-web-toolkit-contributors@googlegroups.com - 3 updates in 1 topic

121 views
Skip to first unread message

Arnaud TOURNIER

unread,
Aug 3, 2017, 7:00:17 AM8/3/17
to Digest recipients

Why not make a polyfill on the native js array loaded with the gwt runtime (dynamically adding needed functions on it) so that it conforms to the Java array type?
Would be ok to do that 99%of the time I think.
It would simplify so much interoperability between them, IMHO...
Arnaud


Le jeu. 3 août 2017 à 12:50, <google-web-tool...@googlegroups.com> a écrit :
Vassilis Virvilis <vas...@gmail.com>: Aug 02 03:41PM +0300

Can you expand a little bit on this? Are there any consequences we need to
look for?
 
Is there a commit to look at?
 
On Mon, Jul 31, 2017 at 8:44 PM, 'Goktug Gokdogan' via GWT Contributors <
 
--
Vassilis Virvilis
Goktug Gokdogan <gok...@google.com>: Aug 02 10:01AM -0700

Unfortunately jsinterop.base doesn't have github repo available yet so you
can't see the commut.
 
Change is asArray method is replaced with asList that looks like this:
 
@JsOverlay
default List<T> asList() {
// Since it is hidden behind Arrays.asList, it is safe to do uncheckedCast.
T[] asArray = Js.uncheckedCast(this);
return Arrays.asList(asArray);
}
 

 
Tony BenBrahim <tony.be...@gmail.com>: Aug 02 02:00PM -0700

In my opinion, there is too much effort put in making Array behave like a
normal Java class when it is not. There are already plenty of good options
in GWT/Java for collections, arrays, etc…
A JavaScript Array is not equivalent to T[], for example this is a
perfectly fine JavaScript Array [1,2,3,"abc", true, {x:1, y:2}] and cannot
be modeled in Java. In my opinion, Array should maintain its JavaScript
nature.
 
For example if the from method actually returned an Array like it does in
JavaScript:
 
public static Array from(JsArrayLike arrayLike);
 
instead of
 
public static final <T, R> R[] from(JsArrayLike<T> arrayLike);
 
then Colin could write
 
Array.from(document.querySelectorAll("...")).forEach(element-> ...);
 
which looks exactly what you would write in JavaScript, and you would not
have to implement toArray and toList on JsArrayLike, which is not mandated
by the spec (the only requirement for ArrayLike is an indexed getter and
the length attribute) Unfortunately,as it is currently, you cannot chain to
other Array methods when T[] is the return type.
 
I do understand the desire for asList(), because in JavaScript, I might
also write
 
for (elem in document.querySelectorAll(...){
...
}
 
but implementing Iterable would be a more desirable solution if possible.
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to google-web-toolkit-co...@googlegroups.com.

Tony BenBrahim

unread,
Aug 3, 2017, 8:14:36 AM8/3/17
to google-web-tool...@googlegroups.com

The compatibility works well when you write all of the code in Java and leave the JavaScript intricacies to GWT.
That completely breaks down when you are working at the JavaScript level with JsInterop, because it allows you to do things you could not do in Java without JSNI or jsinterop.
Take for example this sparse array:

arr=[], arr[0]=10, arr[10]=20; console.log(arr.length); arr.forEach(x => console.log(x));
11
10
20

Even though the length of the sparse array is 11, the iterator only returns the 2 defined elements. The only way to correctly model that behavior is with asIterable() rather than asList(). I have implemented just that, so it is very doable.


On Thu, Aug 3, 2017 at 6:00 AM, Arnaud TOURNIER <lte...@gmail.com> wrote:

Why not make a polyfill on the native js array loaded with the gwt runtime (dynamically adding needed functions on it) so that it conforms to the Java array type?
Would be ok to do that 99%of the time I think.
It would simplify so much interoperability between them, IMHO...
Arnaud


To unsubscribe from this group and stop receiving emails from it send an email to google-web-toolkit-contributors+unsubscribe@googlegroups.com.

--
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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-web-toolkit-contributors/CANjaDnczgsK0o8J5SMcwgbfJq4qg-V%2BXN%2BDH2v3SiYRxEfHyCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Goktug Gokdogan

unread,
Aug 8, 2017, 8:57:23 PM8/8/17
to google-web-toolkit-contributors
JsArrayLike doesn't model arrays and the code in question doesn't return an array, so this is not about filling the gap between native array and java arrays. JavaScript arraylike objects also doesn't have foreach.

The point of JsArrayLike.asList in the API is to bring a reasonable bridge for array like to java world. That could be done with asIterable but if asIterable needs to depend on Symbol.iterator which is not available everywhere. You can do a sparse iteration with JsObect.foreach by providing a callback.


On Thu, Aug 3, 2017 at 5:14 AM, Tony BenBrahim <tony.be...@gmail.com> wrote:

The compatibility works well when you write all of the code in Java and leave the JavaScript intricacies to GWT.
That completely breaks down when you are working at the JavaScript level with JsInterop, because it allows you to do things you could not do in Java without JSNI or jsinterop.
Take for example this sparse array:

arr=[], arr[0]=10, arr[10]=20; console.log(arr.length); arr.forEach(x => console.log(x));
11
10
20

Even though the length of the sparse array is 11, the iterator only returns the 2 defined elements. The only way to correctly model that behavior is with asIterable() rather than asList(). I have implemented just that, so it is very doable.

On Thu, Aug 3, 2017 at 6:00 AM, Arnaud TOURNIER <lte...@gmail.com> wrote:

Why not make a polyfill on the native js array loaded with the gwt runtime (dynamically adding needed functions on it) so that it conforms to the Java array type?
Would be ok to do that 99%of the time I think.
It would simplify so much interoperability between them, IMHO...
Arnaud


To unsubscribe from this group and stop receiving emails from it send an email to google-web-toolkit-contributors+unsu...@googlegroups.com.

--
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+unsu...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "GWT Contributors" group.
Reply all
Reply to author
Forward
0 new messages