One more for the list:

6. When the original JS library contains one or more classes with
methods that receive functions as parameters, what is the best way to
implement these methods? Should there be a generic Function or
Callback class on the GWT side that is used as the function parameter
type? The function that is passed to the JS method may expect to
receive a different number of parameters itself, so one option is to
define the following class in Java:

public class GenericCallback(){
    public void Execute(Object[] Parameters){
       ...
    }
}

With this approach the following JavaScript method:

function doSomething(myCallback){}

Would be translated to the following in GWT:

public final native void doSomething(GenericCallback myCallback)/*-{
      var cb = function(a, b, c, d, e){
             var pars = [a,b,c,d,e];//something fancier than this
             var jcb = this.handler;
             @jcb.GenericCallback::Execute([Ljava/lang/Object;)(pars);
      }
      cb.handler = myCallback;//or something like this that actually
works
      this.doSomething(cb);
}-*/

I don't like the idea of joining all the parameters in an array or of
having a function in Java receive an object array, but otherwise there
would need to be multiple Execute methods with a different number of
parameters or even multiple Callback classes in Java, each with its
own particular Execute method. This wouldn't be so difficult if i was
generating the code manually.

Here's a concrete example of what i'm talking about:
http://code.google.com/apis/gdata/jsdoc/1.8/google/gdata/Entry.html

This class has methods that receive function callbacks (for example
deleteEntry). If you were trying to auto generate a GWT wrapper for
that class how would you handle the methods that receive Function
parameters? (assuming that we're using Overlay Types for the
wrapping).

Bobby

On Apr 18, 4:24 pm, Bobby <bobbysoa...@gmail.com> wrote:
> I'm in the process of trying to dynamically generate a GWT wrapper for
> an existing JS library and i have a few questions which come down to
> best practices for the most part.
>
> 1. When wrapping a JS library with GWT, is it recommended to leave the
> namespaces intact? If the JS library and the GWT wrapper library have
> the same namespaces, is there a chance of a conflict where GWT code
> will overwrite the original namespaces of the JS library? (i don't
> think this is the case but i wanted to verify)
>
> 2. If the JS library that's being wrapped around has classes that may
> need to be constructed from the Java side, then are Overlay Types
> automatically out of the question (in which case plain Java wrapper
> classes would be used) or is it better to still use Overlay Types and
> just expose factory methods for doing the job of the constructors?
>
> 3. If the original JS library has classes where fields are commonly
> accessed directly, as opposed to via getters and setters, then is it
> recommended to remain faithful to the original JS library and expose
> the fields without getters/setters (in which case Overlay Types are
> out of the picture) or ignore this aspect of the original JS library
> and expose getters/setters instead.
>
> 4. If the original JS library has a method that has optional
> parameters, for example, myFunc(a, b) where b may be undefined, should
> a single Java method be added, or should multiple overloaded methods
> be used? For example:
> myFunc(a)
> myFunc(a, b)
>
> 5. Should constants be automatically converted to enumerations or
> should they just be left alone?
>
> If you have some insight on these questions (or any others i missed) i
> would really welcome your input.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to Google-Web-Toolkit@googlegroups.com
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to