Wednesday, July 23, 2014

Re: GWT JS Interopt

HTMLElement implementation is done by the GWT compiler, so the code you say I would not know how to incorporate it. 

For example, I am using Polymer PathObserver:

public interface OpenObserverListener {
 
void onOpen(String oldValue, String newValue);
}

....
....

@JsType(prototype = "PathObserver")
public interface PathObserver {
 
void open(OpenObserverListener handler);
}

....
....

PathObserver observer1 = PathObserverFactory.createObserver(person, "name");
observer1
.open(new OpenObserverListener() {
 
@Override
 
public void onOpen(String oldValue, String newValue) {
    window
().getConsole().log(oldValue);
    window
().getConsole().log(newValue);

 
}
});


And I have the same problem, 
sorry if I have not understood what you have told me. 

Any idea?

Thanks.

El miércoles, 23 de julio de 2014 05:56:19 UTC-3, 田传武 escribió:


On Wed, Jul 23, 2014 at 10:28 AM, Cristian Rinaldi <csri...@gmail.com> wrote:
I have the same problem with addEventListener, the generated code is not exactly as you mention: 

This is my code:

    public interface EventListener<E extends JsObject> {
        void onEvent(E event);
    }

    @JsType(prototype = "HTMLElement")
    public interface HTMLElement extends Element {

        public void setAttribute(String align, String center);

        public void appendChild(HTMLElement element);

        public void addEventListener(String event, EventListener<? extends JsObject> handler);

        @JsProperty
        public void setInnerHTML(String text);

        @JsProperty
        public void setInnerText(String text);
    }

    .....
    HTMLElement button = doc.createElement("button");
    .....
    .....
    button.setInnerText("UPDATE - See the console");

    button.addEventListener("click", new EventListener<JsObject>() {
            @Override
            public void onEvent(JsObject event) {
                window().getConsole().log(event);
            }
    });

    ....
    ....
    ....
    body.appendChild(button);
    .....
    ....

This is the generated code:

 _.onModuleLoad = function() {
  var body_0, button, div, input_0, observer, p, person;
  body_0 = $wnd.document;
  div = body_0.createElement("DIV");
  p = body_0.createElement("P");
  input_0 = body_0.createElement("input");
  button = body_0.createElement("button");
  body_0 = $wnd.document.body;
  person = new clgscm$Person;
  observer = new $wnd.PathObserver(person, "name");
  input_0.bind("value", observer);
  person.name = "Cristian";
  button.innerText = "UPDATE - See the console";
  button.addEventListener("click", new clgsc$gwt_sample$01(this));
  $wnd.console.log("%cWelcome to JSInterop!%c", initValues(jl$getClassLiteralForArray_0(cggl$Ljava_lang_String_2_classLit, 1), $intern_2, 2, 4, ["font-size:1.5em;color:#4558c9;", "color:#d61a7f;font-size:1em;"]));
  div.appendChild(p);
  div.appendChild(input_0);
  body_0.appendChild(div);
  body_0.appendChild(button);
};

createForClass(61, cggl$Ljava_lang_Object_2_classLit);
function clgsc$gwt_sample$01(this$0) {
  this.this$01 = this$0;
  jl$$0init__V__devirtual$0(this);
}

Any Suggestion?

Thanks!!!


El martes, 22 de julio de 2014 07:16:06 UTC-3, 田传武 escribió:
Yes, i didn't use addEventListener. But i has a similar usage:
Java
translated to js
bus.subscribe("some/topic", function(message) {    var body = message.body();    console.log("Name: " + body.name);  });



On Tue, Jul 22, 2014 at 5:41 PM, Henrik <henri...@gmail.com> wrote:
A bonus issue, I saw you did not use addEventListener like the demo does, and I really struggled to make it work.  The generated javascript looks like "addEventListener('click', new xxx(this))" which doesn't work (the key thing here being "new" I'd guess).  I found no other way to call it directly and eventually resorted to doing it from a jsni function instead:
        public static native void jsAddEventListener(Element elem, String event, EventListener listener) /*-{
elem.addEventListener(event, function(ev) { listener.onEvent(ev); });
        }-*/;

Which demo uses addEventListener?


--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/fGIr4sRkz7s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.

--
You received this message because you are subscribed to a topic in the Google Groups "Google Web Toolkit" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-web-toolkit/fGIr4sRkz7s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-we...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" 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 http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment