On 14 juin, 20:28, markmccall <
markwmcc...@gmail.com> wrote:
> I am integrating a 3rd party JavaScript library into my GWT 2.0
> application and I have succeeded in invoking the libary using basic
> JSNI but I want to take the integration even further so that callers
> of the library never have to code any JSNI, if possible. The 3rd
> party library has a class Foo with a JSON structure as a constructore
> parameter.
JSON is a data format, what you're talking about is a JavaScript
object, which you probably generally write directly as an object
literal (the thing within braces, with comma-separated name:value
pairs)
Why not use a JavaScriptObject "overlay type"?
> public void setProp1(String value){ jsonPeer.put ("prop1", value)};
> public void setProp2(String value){ jsonPeer.put ("prop2", value)};
> public asJson() {return jsonPeer.getJavaScriptObject());
> public void setPreLoadHandler(PreLoadHandler handler) { ??? }
> public void setPostLoadHandler(PostLoadHandler handler) { ??? }
>
> }
>
> Am I on the right track? Is there a better way?
Re-written as an overlay type:
public final class Config extends JavaScriptObject {
public static Config newInstance() /*-{ }-*/;
protected Config() { }
public native void setProp1(String value) /*-{ this.prop1 = value; }-
*/;
public native void setProp2(String value) /*-{ this.prop2 = value;}-
*/;
public native void setPreLoadHandler(PreLoadHandler handler) /*-{
var that = this;
this.onBeforeCompute = $entry(function(someparam) {
handler.@my.app.client.PreLoadHandler::onBeforeCompute(Lcom/
google/gwt/core/client/JavaScriptObject;)(someparam);
});
}-*/;
public native void setPostLoadHandler(PostLoadHandler handler) /*-{
var that = this;
this.onBeforeCompute = $entry(function(someparam) {
handler.@my.app.client.PostLoadHandler::onAfterCompute(Lcom/
google/gwt/core/client/JavaScriptObject;Lcom/google/gwt/core/client/
JavaScriptObject;)(someparam1, someparam2);
});
}-*/;
}