Friday, September 15, 2017

Re: Data class in JsInterop

I didn't know you could put @JsIgnore in the constructor...

Aah now I see that your JsClass is not a native type.

What I am usually doing is

@JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object")
public class JsClass {
  public String a,b; 

  @JsOverlay
  public static JsClass create(String a, String b) {
     final JsClass c = new JsClass();
     c.a = a;
     c.b = b;
     return c;
  }
}

Don't know if the @JsIgnore/Constructor/native trick would work. So far I am using @JsOverlay/static creator/native instead.

I will try it out some time.

Hope that helps

    Vassilis

On Fri, Sep 15, 2017 at 2:48 PM, Kirill Prazdnikov <pkirill@gmail.com> wrote:
Hi, I need the following code needs to be generated:

function f(a,b) { return { a:a, b:b }; } 

This is super - easy in JSNI mode. However to be in the modern stream and to be portable I trying to do that using JsInterop

@JsType(namespace = JsPackage.GLOBAL)
public class JsClass {
  public String a,b; 

  @JsIgnore
  public JsClass(String a, String b) { this.a=a; this.b=b; }
}

It seems to be working, however in the compiled code I see something super strange I can not understand:

function a_g$(){
  a_g$ = Object;
}

function Ezf_g$(){
  Ezf_g$ = Object;
  a_g$();
}

function a3i_g$(a_0_g$, b_0_g$){
  Ezf_g$();
  i_g$.call(this);
  this.$init_1758_g$();
  this.a = a_0_g$;
  this.b = b_0_g$;
}

_.$init_1758_g$ = function Fzf_g$(){
  Ezf_g$();
}


where Ezf_g$ seems to be doing nothing, i_g$.call(this) is doing nothing, this.$init_1758_g$() is doing nothing, and a_g$() is doing nothing. 

What is this all for ? What am I missing? 
How go get the line I need with JsInterop ?

Thanks 


--
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