Yes, that does work. However, it's awkward.

For example, if someone using jquery were to use my API, it would be
nice for them to be able to do this:
$(function() {
    MyAPI.XXX(...);
});

Not this:
myApiReady() {
   MyAPI.XXX(...);
}

Big deal right? ...but imagine how it scales. Say you depend on three
GWT API's. Now you're looking at something like this:

var readyStates = {'one' : false, 'two' : false, 'three' : false };
myReallyActuallyReallyReadyFunction() {
     ...
}
function myApiOneReady() {
    readyStates.one = true;
    if (readyStates.one && readyStates.two && readyStates.three)
        myReallyActuallyReallyReadyFunction();
};
function myApiTwoReady() {
    readyStates.two = true;
    if (readyStates.one && readyStates.two && readyStates.three)
        myReallyActuallyReallyReadyFunction();
};
function myApiThreeReady() {
    readyStates.three = true;
    if (readyStates.one && readyStates.two && readyStates.three)
        myReallyActuallyReallyReadyFunction();
};

Ouch.

I still don't understand why the onModuleLoad kicks off after the
onLoad event; unless GWT is specifically waiting for the onLoad event
before it kicks off its own internal processes.

I suppose that vaguely makes sense, but it means that as an API
platform it's vastly unuseful, unless there's a way to turn it off.


~
Doug.


On Aug 6, 3:06 pm, olivier nouguier <olivier.nougu...@gmail.com>
wrote:
> hi,
>  On "simple"  solution:
>
> * In your html/js code define a:
>
> function toBeCalledByGWT{
>  NetLoaderAPI.startUnitTests();
>
> }
>
> * Call this function by JNSI at the end of onModuleLoad().
>
> public void onModuleLoad(){
> /*
> ... Standard GWT code.
> */
>
> callJSInPage();
>
> }
>
> public void native callJSInPage() /*-{
>   $wnd.toBeCalledByGWT()();
>
> }-*/;
>
> HIH
>
>
>
> On Thu, Aug 6, 2009 at 8:09 AM, dougx <douglas.lin...@gmail.com> wrote:
>
> > How can you wait until after onModuleLoad() has been invoked for an
> > application in external javascript?
>
> > Should be quite a simple matter:
> > - I have a GWT aplication that publishes a static JS API via JSNI.
> > - I have a page that uses that API.
>
> > I should be able to do this:
> > <body onload="apiTest();">
> > <script src="js/NetLoaderAPI/NetLoaderAPI.nocache.js"></script>
> > <script>
> > function apiTest() {
> >      NetLoaderAPI.startUnitTests();
> > }
> > </script>
> > </body>
>
> > However, I can't use it, beacause I get an error like this:
> > "TypeError: window.NetWorkerAPI is undefined"
>
> > What? How is there some kind of delay between scripts loaded and run,
> > and the document ready event?
>
> > I have, for reference, compiled in xs mode, so the gwt code is not
> > being loaded in an external iframe.
>
> > ie. The API js is being included directly into the page header,
> > firebug shows it as:
> > <script src="http://localhost:8080/js/NetLoaderAPI/
> > 9B08C2C4C155D60688C70B5ED70CC3CA.cache.js">...</script>
>
> > ~
> > Doug.
>
> --
> A coward is incapable of exhibiting love; it is the prerogative of the
> brave.
> --
> Mohandas Gandhi
--~--~---------~--~----~------------~-------~--~----~
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