I will add 4 and 5 arg interfaces. I think I can include something equivalent with your above code. I already have getters/setters and is defined functions for objects. All you would need to do is pass $wnd into these. Let me have a play around and see what I can come up with.
On Thursday, June 2, 2016 at 4:50:08 PM UTC-4, Hristo Stoyanov wrote: > > Thanks Paul, > I was about to start releasing similar code > <https://github.com/hrstoyanov/gwt-functions/tree/master/src/main/java/org/gwtproject/functions/client> > . > It does not make sense to do the same thing twice and obviously such > utility code is necessary. So, I will use your project as it seems a bit > more advanced and start contributing! > > Quick request before I adopt it in my libraries today: > - Can you add functional interfaces with 4 and 5 arguments. I think you > have them up to 3 only, but I do face JS libraries with 4 and 5. > - Do you have similar utils as the one below? If not, would it be possible > to incorporate something like it in your projects? > > /** > * JavaScript global variables and functions utils. > * > */ > //@JsType(isNative = true, namespace = JsPackage.GLOBAL) > public abstract class VariablesAndFunctions { > > public native static <T> T eval(String expresion); > > // @JsOverlay > // public boolean isJSVariableDefined(String jsVariableName) { > // return Boolean.TRUE.equals(eval("!!window[" + jsVariableName + > "]")); > // } > // > // @JsOverlay > // public static <T> T getJSVariableValue(String jsVariableName) { > // return eval("!!window[" + jsVariableName + "]"); > // } > public static native String getStringJSVariable(String jsVar) /*-{ > return $wnd[jsVar].toString(); > }-*/; > > public static native Object getJSVariable(String jsVar) /*-{ > return $wnd[jsVar]; > }-*/; > > public static native boolean isVariableDefined(String jsVar)/*-{ > return !!$wnd[jsVar]; > }-*/; > > public static native boolean isFunctionDefined(String functionName)/*-{ > return typeof functionName == 'function'; > }-*/; > } > > > > On Thursday, June 2, 2016 at 11:57:46 AM UTC-7, Paul Stockley wrote: >> >> I have committed an initial version of gwt-interop-utils. >> >> https://github.com/GWTReact/gwt-interop-utils >> >> This library provides some common utilities for working with JsInterop >> e.g. >> >> 1) Object Literal support >> 2) Shared JSON compatible structures >> 3) Common functional interfaces >> 4) JSON utilities >> 5) Low level Javascript utilities. >> >> One of my major goals was to enable creating complex object literals with >> arrays and maps that could be represented by a single class, accessible >> both on the client and server. You can now define a class such as >> >> import gwt.interop.utils.shared.collections.Array; >> import gwt.interop.utils.shared.collections.StringMap; >> import gwt.interop.utils.shared.valuetypes.NumberValue; >> >> @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") >> public class CommonDataObject { >> public int intVal; >> public double doubleVal; >> public boolean booleanVal; >> public String stringVal; >> public NumberValue numberVal; >> public Array<String> anArray; >> public StringMap<String> aMap; >> public CommonDataObject2 embeddedObj; >> >> @JsOverlay >> public static CommonDataObject create() { >> CommonDataObject o = new CommonDataObject(); >> o.intVal = 10; >> o.doubleVal = 20.20; >> o.booleanVal = true; >> o.stringVal = "A String Value"; >> o.numberVal = NumberValue.from(10); >> o.anArray = Array.create(); >> >> o.anArray.set(0, "ArrayValue1"); >> o.anArray.set(2, "ArrayValue2"); >> o.anArray.set(2, "ArrayValue3"); >> >> o.aMap = StringMap.create(); >> >> o.aMap.put("v1", "A Map Value 1"); >> o.aMap.put("v2", "A Map Value 2"); >> >> o.embeddedObj = new CommonDataObject2(); >> o.embeddedObj.field1 = "An embbeded object field"; >> return o; >> } >> >> @JsOverlay >> public final String convolutedSharedMethod(String someArg) { >> StringBuilder o = new StringBuilder(); >> >> anArray.forEachElem((e) -> { >> o.append(aMap.get(someArg)); >> o.append(embeddedObj.field1); >> o.append(e); >> }); >> >> return o.toString(); >> } >> } >> >> @JsType(isNative = true, namespace = JsPackage.GLOBAL, name = "Object") >> public class CommonDataObject2 { >> public String field1; >> } >> >> Instances of this class can be encoded to/from JSON using standard JSON >> functions. You can also create/use the same class on the server and full >> emulation is provided. Given this setup, it gives you a lot of the benefits >> of GWT RPC (i.e. shared data objects and behavior across client/server) >> without the code bloat or performance hit. >> >> Before I publish it to Maven, I still need to finish the docs and do some >> more testing. I am also waiting for some compiler fixes to land. >> >> Please take a look and let me know if there are any changes/additions you >> would like. >> > -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/google-web-toolkit. For more options, visit https://groups.google.com/d/optout.
