Re: [gwt-contrib] Re: JsInterop & collections

2017-05-10 Thread 'Daniel Kurka' via GWT Contributors
In general we consider JSNI deprecated and it will not be present in the new J2CL transpiler. JsInterop (together with Jsinterop base) is powerful enough to do all things you were doing in JS. public class Helper { @JsMethod(name = "Array.prototype.push.apply", namespace=JsPackage.GLOBAL) sta

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-10 Thread Marcin Okraszewski
Looks better indeed. Are there also some other reasons not to use JSNI? Eg. performance, or it is going to be removed in future? How would I call Array.prototype.push.apply(arrayList, value); via JsInterop? Or if I wanted to add a function to an existing object? Thank you, Marcin On Wednesday

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-10 Thread Marcin Okraszewski
Thanks for hint. Indeed, it is the same concept here. The only difference in parser is that I targeted in a List implementation that would still work as array in JS, so I can share exactly the same model between JS and GWT. I also plan to use JsInterop to access objects, while I see overlay type

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-10 Thread 'Daniel Kurka' via GWT Contributors
First of all do not use JSNI going forward. Use elemental2 (or define your own JSON.parse): Without elemental2: @JsType(isNative=true, namespace = JsPackage.GLOBAL); public class JSON { public static Object parse(String s, Reviver r); } @JsFunction public interface Reviver { public Object ru

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-10 Thread support
I am still new to GWT (so this code is probably naive), but I implemented this JSON parse wrapper which performs "transparent" conversion of JS arrays to java.util.List and using replacer/reviver functions: https://github.com/bpilot/jclosure/blob/master/src/main/java/ailabs/jclosure/client/encod

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-10 Thread Marcin Okraszewski
I've done something that I think is so far the closest to what I want to achieve - the same object behaving as List in Java and as array in JS. Actually it can be seen in Java as either list or array - both work :-) First I declare JsArray: @JsType(isNative=true, name="Array", namespace=JsPacka

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-09 Thread 'Ray Cromwell' via GWT Contributors
I think it would be better to use a JsArrayListAdapter in order to prevent making copies all over the place, and also making mutations write-through on both sides e.g. public class JsArrayListAdapter extends AbstractList { public JsArrayListAdapter(ArrayLike blah) { this.array = blah; }

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-09 Thread 'Goktug Gokdogan' via GWT Contributors
Yes, theoretically you should be able to use the second parameter on Json.parse Json.stringify for conversion back and forth between java collections and js primitives. In this model, your javascript code needs to use Java collection APIs. > java.util.Arrays.asList() should be enough keep in mind

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-09 Thread Thomas Broyer
On Tuesday, May 9, 2017 at 4:34:48 PM UTC+2, Marcin Okraszewski wrote: > > There is indeed something in it. Actually you could have some type of > naming convention, like in TJSON ( > https://tonyarcieri.com/introducing-tjson-a-stricter-typed-form-of-json) > or TypedJson (https://www.npmjs.com/

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-09 Thread Marcin Okraszewski
There is indeed something in it. Actually you could have some type of naming convention, like in TJSON (https://tonyarcieri.com/introducing-tjson-a-stricter-typed-form-of-json) or TypedJson (https://www.npmjs.com/package/typed-json) to figure out proper types. But then I would need to create eg

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-09 Thread Thomas Broyer
On Tuesday, May 9, 2017 at 12:08:12 PM UTC+2, Marcin Okraszewski wrote: > > In short I would like JS arrays to be visible in GWT as a List and objects > parsed from JSON also as a Map. > > Maybe I'll try one more time to explain what we have. We share model > between server and GWT in form of j

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-09 Thread Jens
> I believe it was in plans with @JsConvert – see slides 67 – 69. > https://docs.google.com/file/d/0ByS1wxINeBWjeGYxbkJpamxFZ28/edit > I think this is more meant to be used with non-native JsTypes. When you have a JsType implemented in Java and some JavaScript gives you JS through the Java ob

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-09 Thread Marcin Okraszewski
In short I would like JS arrays to be visible in GWT as a List and objects parsed from JSON also as a Map. Maybe I'll try one more time to explain what we have. We share model between server and GWT in form of java interfaces. Those interfaces are declared as return types of Jersey services, which

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-08 Thread 'Goktug Gokdogan' via GWT Contributors
What do you mean exactly by "collection support in JsInterop"? From you description I only understand that you want to keep using java collection API for existing & server side code. If you want use your JavaScript array/map instance from Java, you need an adaptor; doesn't matter who provides. And

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-08 Thread Manuel Carrasco Moñino
If in your model is enough to have Collections/Lists based on ArrayList you can easily convert from JsArrays to ArrayLists and vice-versa by using a bit of JSNI since the ArrayList implementation in GWT relies on a javascript array. Take a look to this code used in the gwt-polymer-elements library

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-08 Thread Marcin Okraszewski
Basically what we need it for is REST. Currently we use AutoBeans, but we want to change it because we need to pass the model to JS too; secondly AutoBeans generate a lot of code. We would like to still preserve shared model with the server. So, JsInterop seems the most natural choice, except i

Re: [gwt-contrib] Re: JsInterop & collections

2017-05-08 Thread 'Ray Cromwell' via GWT Contributors
The adapter class adds overhead though and you need to convert into and out of it every time you pass it to JS. At that point you may as well use Java.util.List and write an adapter around JS array. On Mon, May 8, 2017 at 7:10 AM Jens wrote: > IMHO if you want a JavaScript array, set, map behav

[gwt-contrib] Re: JsInterop & collections

2017-05-08 Thread Jens
IMHO if you want a JavaScript array, set, map behave the same as a Java collection, so you can use it with other libraries, you should write an adapter class that implements the Java API and operates internally on the JavaScript data type. Basically do not rely on invisible magic. That could e