Re: [gwt-contrib] NodeList and JsArrayList.asArray

2017-08-02 Thread Tony BenBrahim


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  R[] from(JsArrayLike 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 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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/0a3d1d8b-2481-474f-8b97-1ed2e7b02421%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gwt-contrib] NodeList and JsArrayList.asArray

2017-08-02 Thread 'Goktug Gokdogan' via GWT Contributors
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 asList() {
// Since it is hidden behind Arrays.asList, it is safe to do uncheckedCast.
T[] asArray = Js.uncheckedCast(this);
return Arrays.asList(asArray);
  }

​

On Wed, Aug 2, 2017 at 5:41 AM, Vassilis Virvilis  wrote:

> 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 <
> google-web-toolkit-contributors@googlegroups.com> wrote:
>
>> It is fixed internally. asArray API replaced with asList API
>>
>> On Mon, Jul 24, 2017 at 3:11 PM, Goktug Gokdogan 
>> wrote:
>>
>>> For following code:
>>>
>>> class A {
>>>   T[] asArray {}..
>>> }
>>>
>>> A st;
>>> String[] arr = st.asArray();
>>>
>>> I wasn't expecting an erasure cast at the call site for this but seems
>>> like I was wrong and erasure cast seems right here otherwise you cannot
>>> guarantee that arr[0] which won't have a cast to return String.
>>>
>>> We should be able to repro this in jsinterop.base; will take a look.
>>>
>>>
>>> On Sun, Jul 23, 2017 at 8:18 PM, Colin Alworth 
>>> wrote:
>>>
 Using GWT 2.8.1, I'm trying to iterate through items found via a query
 selector:

 Arrays.asList(document.querySelectorAll("button.with-some-class").
 asArray()).forEach(
 item -> doSomething(item)
 );

 Unfortunately, this seems to always fail - querySelectorAll returns a
 NodeList, and while asArray() seems to specify Js.uncheckedCast,
 the resulting generated code is

 $forEach_1(new Arrays$ArrayList(*castToJsArray*(($clinit_DomGlobal() ,
 document_0).querySelectorAll('button.with-some-class'))), new
 SampleClass$lambda$0$Type);

 Predictable, the bolded castToJsArray causes an exception at runtime,
 since a NodeList isn't actually a JS Array at all.

 Is there a correct way to do this, or perhaps a nicer way to iterate
 through NodeLists?

 I assume this should be a bug filed against jsinterop-base, but am not
 seeing a repo for it, or is this a bug in GWT itself?

 --
 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-contributor
 s+unsubscr...@googlegroups.com.
 To view this discussion on the web visit https://groups.google.com/d/ms
 gid/google-web-toolkit-contributors/4764126b-ed92-409a-bb4b-
 d1d1fead2e3c%40googlegroups.com
 
 .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/google-web-toolkit-contributors/CAN%3DyUA3o45d%3DO9nDyVX
>> 0z_gb%2BTzkgAh_EVwOdfmO2qhxNQ5p3Q%40mail.gmail.com
>> 
>> .
>>
>> 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 Contributors" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/google-web-toolkit-contributors/CAKbOjEycK-P-
> vSSa1TcwzcdaLWrCiFg0z3QTqKbH9JPtVYPMjA%40mail.gmail.com
> 
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

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


Re: [gwt-contrib] NodeList and JsArrayList.asArray

2017-08-02 Thread Vassilis Virvilis
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 <
google-web-toolkit-contributors@googlegroups.com> wrote:

> It is fixed internally. asArray API replaced with asList API
>
> On Mon, Jul 24, 2017 at 3:11 PM, Goktug Gokdogan 
> wrote:
>
>> For following code:
>>
>> class A {
>>   T[] asArray {}..
>> }
>>
>> A st;
>> String[] arr = st.asArray();
>>
>> I wasn't expecting an erasure cast at the call site for this but seems
>> like I was wrong and erasure cast seems right here otherwise you cannot
>> guarantee that arr[0] which won't have a cast to return String.
>>
>> We should be able to repro this in jsinterop.base; will take a look.
>>
>>
>> On Sun, Jul 23, 2017 at 8:18 PM, Colin Alworth 
>> wrote:
>>
>>> Using GWT 2.8.1, I'm trying to iterate through items found via a query
>>> selector:
>>>
>>> Arrays.asList(document.querySelectorAll("button.with-some-class").
>>> asArray()).forEach(
>>> item -> doSomething(item)
>>> );
>>>
>>> Unfortunately, this seems to always fail - querySelectorAll returns a
>>> NodeList, and while asArray() seems to specify Js.uncheckedCast,
>>> the resulting generated code is
>>>
>>> $forEach_1(new Arrays$ArrayList(*castToJsArray*(($clinit_DomGlobal() ,
>>> document_0).querySelectorAll('button.with-some-class'))), new
>>> SampleClass$lambda$0$Type);
>>>
>>> Predictable, the bolded castToJsArray causes an exception at runtime,
>>> since a NodeList isn't actually a JS Array at all.
>>>
>>> Is there a correct way to do this, or perhaps a nicer way to iterate
>>> through NodeLists?
>>>
>>> I assume this should be a bug filed against jsinterop-base, but am not
>>> seeing a repo for it, or is this a bug in GWT itself?
>>>
>>> --
>>> 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+unsubscr...@googlegroups.com
>>> .
>>> To view this discussion on the web visit https://groups.google.com/d/ms
>>> gid/google-web-toolkit-contributors/4764126b-ed92-409a-bb4b-
>>> d1d1fead2e3c%40googlegroups.com
>>> 
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/google-web-toolkit-contributors/CAN%3DyUA3o45d%
> 3DO9nDyVX0z_gb%2BTzkgAh_EVwOdfmO2qhxNQ5p3Q%40mail.gmail.com
> 
> .
>
> 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 
Contributors" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit-contributors+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAKbOjEycK-P-vSSa1TcwzcdaLWrCiFg0z3QTqKbH9JPtVYPMjA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gwt-contrib] NodeList and JsArrayList.asArray

2017-07-31 Thread 'Goktug Gokdogan' via GWT Contributors
It is fixed internally. asArray API replaced with asList API

On Mon, Jul 24, 2017 at 3:11 PM, Goktug Gokdogan  wrote:

> For following code:
>
> class A {
>   T[] asArray {}..
> }
>
> A st;
> String[] arr = st.asArray();
>
> I wasn't expecting an erasure cast at the call site for this but seems
> like I was wrong and erasure cast seems right here otherwise you cannot
> guarantee that arr[0] which won't have a cast to return String.
>
> We should be able to repro this in jsinterop.base; will take a look.
>
>
> On Sun, Jul 23, 2017 at 8:18 PM, Colin Alworth  wrote:
>
>> Using GWT 2.8.1, I'm trying to iterate through items found via a query
>> selector:
>>
>> Arrays.asList(document.querySelectorAll("button.with-some-class").asArray
>> ()).forEach(
>> item -> doSomething(item)
>> );
>>
>> Unfortunately, this seems to always fail - querySelectorAll returns a
>> NodeList, and while asArray() seems to specify Js.uncheckedCast,
>> the resulting generated code is
>>
>> $forEach_1(new Arrays$ArrayList(*castToJsArray*(($clinit_DomGlobal() ,
>> document_0).querySelectorAll('button.with-some-class'))), new
>> SampleClass$lambda$0$Type);
>>
>> Predictable, the bolded castToJsArray causes an exception at runtime,
>> since a NodeList isn't actually a JS Array at all.
>>
>> Is there a correct way to do this, or perhaps a nicer way to iterate
>> through NodeLists?
>>
>> I assume this should be a bug filed against jsinterop-base, but am not
>> seeing a repo for it, or is this a bug in GWT itself?
>>
>> --
>> 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+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit https://groups.google.com/d/ms
>> gid/google-web-toolkit-contributors/4764126b-ed92-409a-bb4b-
>> d1d1fead2e3c%40googlegroups.com
>> 
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAN%3DyUA3o45d%3DO9nDyVX0z_gb%2BTzkgAh_EVwOdfmO2qhxNQ5p3Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [gwt-contrib] NodeList and JsArrayList.asArray

2017-07-24 Thread 'Goktug Gokdogan' via GWT Contributors
For following code:

class A {
  T[] asArray {}..
}

A st;
String[] arr = st.asArray();

I wasn't expecting an erasure cast at the call site for this but seems like
I was wrong and erasure cast seems right here otherwise you cannot
guarantee that arr[0] which won't have a cast to return String.

We should be able to repro this in jsinterop.base; will take a look.


On Sun, Jul 23, 2017 at 8:18 PM, Colin Alworth  wrote:

> Using GWT 2.8.1, I'm trying to iterate through items found via a query
> selector:
>
> Arrays.asList(document.querySelectorAll("button.with-some-class").asArray
> ()).forEach(
> item -> doSomething(item)
> );
>
> Unfortunately, this seems to always fail - querySelectorAll returns a
> NodeList, and while asArray() seems to specify Js.uncheckedCast,
> the resulting generated code is
>
> $forEach_1(new Arrays$ArrayList(*castToJsArray*(($clinit_DomGlobal() ,
> document_0).querySelectorAll('button.with-some-class'))), new
> SampleClass$lambda$0$Type);
>
> Predictable, the bolded castToJsArray causes an exception at runtime,
> since a NodeList isn't actually a JS Array at all.
>
> Is there a correct way to do this, or perhaps a nicer way to iterate
> through NodeLists?
>
> I assume this should be a bug filed against jsinterop-base, but am not
> seeing a repo for it, or is this a bug in GWT itself?
>
> --
> 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+unsubscr...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/
> msgid/google-web-toolkit-contributors/4764126b-ed92-
> 409a-bb4b-d1d1fead2e3c%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/CAN%3DyUA3f4MZBO%3DDE3GFf_jHRH%3DPu2-pst%3DhSJh2_M9CrrxmH1A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


[gwt-contrib] NodeList and JsArrayList.asArray

2017-07-23 Thread Colin Alworth
Using GWT 2.8.1, I'm trying to iterate through items found via a query 
selector:

Arrays.asList(document.querySelectorAll("button.with-some-class").asArray
()).forEach(
item -> doSomething(item)
);

Unfortunately, this seems to always fail - querySelectorAll returns a 
NodeList, and while asArray() seems to specify Js.uncheckedCast, 
the resulting generated code is 

$forEach_1(new Arrays$ArrayList(*castToJsArray*(($clinit_DomGlobal() , 
document_0).querySelectorAll('button.with-some-class'))), new 
SampleClass$lambda$0$Type);

Predictable, the bolded castToJsArray causes an exception at runtime, since 
a NodeList isn't actually a JS Array at all.

Is there a correct way to do this, or perhaps a nicer way to iterate 
through NodeLists?

I assume this should be a bug filed against jsinterop-base, but am not 
seeing a repo for it, or is this a bug in GWT itself?

-- 
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-web-toolkit-contributors/4764126b-ed92-409a-bb4b-d1d1fead2e3c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.