Re: Passing Object Literal to Javascript method ?

2013-10-07 Thread Ed
FYI: they changes the "instanceof Array" statement in the external lib ;) -- 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+unsubscr...@go

Re: Passing Object Literal to Javascript method ?

2013-10-06 Thread Ed Bras
The external js lib I am using as the following condtion on an input arg I specify: if (value instanceof Array) { This is a problem for me, as the array I pass isn't seen an array as GWT runs in an iframe (such that the lib complaints it's not an arry). Like @Thomas explains in his post

Re: Passing Object Literal to Javascript method ?

2013-10-04 Thread Jens
yeah just found the reason: https://gwt.googlesource.com/gwt/+/6a69ac1077321af7e60480af70f513bfa90d21f5 But it looks like its already refactored and JavaScriptObject.createFunction() isn't used anymore. -- J. -- You received this message because you are subscribed to the Google Groups "Googl

Re: Passing Object Literal to Javascript method ?

2013-10-04 Thread Thomas Broyer
Something similar (but can't remember if it actually used createFunction) was used to "reset" an XHR's onreadystatechange to avoid some leak or crash in some browser (IE?) On Friday, October 4, 2013 4:33:03 PM UTC+2, Ed wrote: > > @Jens: I was thinking the same, but "somebody" has added with a g

Re: Passing Object Literal to Javascript method ?

2013-10-04 Thread Ed Bras
@Jens: I was thinking the same, but "somebody" has added with a goal I thought, so there would be any use of it ;) On Fri, Oct 4, 2013 at 4:28 PM, Jens wrote: > BTW: where can I find an example of using the method JavascriptObject.** >> createFunction()? >> I think it can be used to wrap a java

Re: Passing Object Literal to Javascript method ?

2013-10-04 Thread Jens
> > BTW: where can I find an example of using the method > JavascriptObject.createFunction()? > I think it can be used to wrap a java instance and forward a js call to a > call in the instance, but don't understand how this can be done through > this function creation method (can't find any exa

Re: Passing Object Literal to Javascript method ?

2013-10-04 Thread Ed Bras
BTW: where can I find an example of using the method JavascriptObject.createFunction()? I think it can be used to wrap a java instance and forward a js call to a call in the instance, but don't understand how this can be done through this function creation method (can't find any example on the net)

Re: Passing Object Literal to Javascript method ?

2013-10-04 Thread Ed Bras
@Thomas: that seems to work (very obvious btw). I forgot to mention that I tried that before, and didn't work, but I remember that it works once (calling the callback), but I think that has another cause. Thanks... Anyway, there isn't a special operation needed in this case, I though I might have t

Re: Passing Object Literal to Javascript method ?

2013-10-04 Thread Thomas Broyer
if (command != null) ? On Friday, October 4, 2013 3:01:04 PM UTC+2, Ed wrote: > > What is the correct way to check if a java object is not null in > javascript? > Exampe: > private native performIntern(JsArray elements, int > duration, JavaScriptObject options, HasOnComplete command) /*-{ >

Re: Passing Object Literal to Javascript method ?

2013-10-04 Thread Ed Bras
What is the correct way to check if a java object is not null in javascript? Exampe: private native performIntern(JsArray elements, int duration, JavaScriptObject options, HasOnComplete command) /*-{ var func = null; if (typeof command !== 'undefined') { func = function() { comma

Re: Passing Object Literal to Javascript method ?

2013-10-04 Thread Ed Bras
What is the correct way to check if a java object is not null in javascript? Exampe: private native performIntern(JsArray elements, int duration, JavaScriptObject options, HasOnComplete command) /*-{ if (typeof command !== 'undefined') { func = function() { comma...@com.bla.HasOnComplete::onComp

Re: Passing Object Literal to Javascript method ?

2013-10-03 Thread Ed Bras
@Jens: btw, do you know how to tell Eclipse to "not" format the native java methods ? (CTR+SHIFT+ F) I noticed @Thomas mentioning on SO that it's probably done by the JS formatter in Eclipse. But I wasn't able to disable it. The only way I got it disabled by using the Eclipse tags: @formatter:off a

Re: Passing Object Literal to Javascript method ?

2013-10-03 Thread Ed Bras
Thanks @Jens, I was just playing with it and it was driving me crazy as it didn't work and because of your example I noticed that the "dot" before the @ was missing :(... I hate this cryptic JS errors :(... Anyway, I ended up with this method added to the PropertyBuilder that works: private stati

Re: Passing Object Literal to Javascript method ?

2013-10-03 Thread Jens
Add a Callback parameter to your JSNI method and call it from a pure JavaScript callback function. public native CssHolder perform(Element e, int duration, JavaScriptObject options, Callback callback) /*-{ options.onComplete = function() { callback.@::onComplete()(); // maybe cleanup

Re: Passing Object Literal to Javascript method ?

2013-10-03 Thread Ed
Next challenge: how to provde a callback function as property? In Javascript you have something like: CssMod.perform(element, 1.5, {width:100, onComplete:myFunction}); function myFunction() { console.log("finished"); } But how can I do this in GWT Java code :( ? That is: specify a "link" to a

Re: Passing Object Literal to Javascript method ?

2013-10-03 Thread Ed Bras
To Wrap it up: I ended up having a PropertiesBuilder interface: public interface PropertiesBuilder extends Builder { PropertiesBuilder set(String key, T value); } and a Js version: public final class JsPropertyBuilder implements PropertiesBuilder, IsJavaScriptObject { private final JavaScriptObjec

Re: Passing Object Literal to Javascript method ?

2013-10-03 Thread Ed Bras
Fluent api, niceeThanks for your ideas. -- 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+unsubscr...@googlegroups.com. To post to thi

Re: Passing Object Literal to Javascript method ?

2013-10-03 Thread Jens
I would build it like: Mutable version: class Options extends JavaScriptObject { public native Options with(String option, String value) /*-{ this[option] = value; return this; }-*/; } Options options = Options.createObject() .with("opacity", "0.5") .with("width", "100"

Re: Passing Object Literal to Javascript method ?

2013-10-03 Thread Ed Bras
Played some more and I create a literal Js Object, or some called Option Js object, like this: private JavaScriptObject createOptions(final String name, final String value) { return addOptions(JavaScriptObject.createObject(), name, value); } private native JavaScriptObject addOptions(final JavaS

Re: Passing Object Literal to Javascript method ?

2013-10-03 Thread Ed Bras
@Jens: thanks, I am going for the latter options, that seems to work well and safe. The builder pattern was exactly why I want the above construction ;) (using the GWT css classes for the naming) I am just considering if directly creating a JavascriptObject through a Builder class wouldn't be bet

Re: Passing Object Literal to Javascript method ?

2013-10-02 Thread Jens
I think you have to write public final native CssHolder perform(Element element, int duration, String args) /*-{ return $wnd.CssMod.perform(element, eval('obj = ' + args + ';')); }-*/; perform(element, "{ \"opacity\":2}"); Maybe the following also works: public final native CssHolder p

Passing Object Literal to Javascript method ?

2013-10-02 Thread Ed
Please some help on the following. How to pass an Object literal to a javascript function I have a javascript function that looks like: public final native CssHolder perform(Element element, int duration) /*-{ return $wnd.CssMod.perform(element, {opacity: 0.2}); }-*/; This works if I call it fro