I'm not 100% following your question, so excuse me if my answer does not match your question.
Why would you need to have a toBeCalledByGWT for every method you want to expose from GWT ? I presume you have created an API in GWT and want to expose it outside of GWT ? Just make sure that the onModuleLoad exposes all the methods (one way or another) and at the end you just call one method on the window object to indicate that the API is ready to be used. So you JS code just needs to wait until that method is invoked before starting If you want to use multiple GWT APIs this way, I guess the best thing to do is to have one onModuleLoad that invokes the injection of all the APIs in JS and then call one callback to kickstart your application. The idea of GWT is that you compile everything in one application to improve optimisations and to have a small as possible JS. Why is the GWT API not fully initialized ? Well because it is actually loaded by a hidden IFrame. Additionally with GWT 2.0 we will be able to actually load parts on demand through runAsync support. David On Thu, Aug 6, 2009 at 10:11 AM, dougx<[email protected]> wrote: > > 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 <[email protected]> > 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 <[email protected]> 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 [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/Google-Web-Toolkit?hl=en -~----------~----~----~----~------~----~------~--~---
