my applet downloads the code. since java automtically does not return until the code has finished downloading and executing, there are no problems with syncronization.
my applet / js code combines and wraps the downloaded code in a new
javascript function.
this function is passed a variable called 'override'. this tels
it that if the code has alreayd been executed, there is no need to rerun
it unless the override variable is set to true.
because the code has already fully downloaded and the applet is finished it's bit before it is executed, the applet is free to download another file while the original code is being executed.
here is a simple example:
afroapi/api/layer.js
if (AfroGUI.Layer&&!override) return; // do not
run twice unless told to.
// if required functions are not there, download
them now.
// control does not return to this function until
the new code is downloaded and executed.
if (!AfroGUI.BaseObj.prototype.addChild) AfroAPI.include('afroapi.api.base');
if (!AfroGUI.Document) AfroAPI.include('afroapi.api.document');
AfroGUI.Layer=function() {
this is the same with ALL of my widgets. this means that in the html file, I only need to manually include the single file.
eg. AfroAPI.include('afroapi.api.layer');
this will automtically load the base, document and layer code so that my html files are smaller and simpler.
Daniel LaLiberte wrote:
Joachim Lundgren writes:--
..
> Imagine a file A.js that requires B.js and checks if the file already
> has been loaded else loads it (with writing a SCRIPT tag) the
> required file (B.js) is loaded _after_ the current JavaScript-block
> or file has been executed - not inserted instead of the SCRIPT tag
> that was written.
>
> If you can come up with a solution I'll be more than interested!If A.js requires B.js, it should be possible to queue up execution of
the code in A.js by wrapping all the code, including all function
definitions, in a function definition, say A_code. This may require
some changes to how variables are assigned. I.e. top level var
declarations. After you write out the SCRIPT tag to cause B.js to be
loaded, write out another SCRIPT block to call A_code().But there is still a problem. If B.js in turn requires C.js, and we
similarly wrap the B code with a B_code function definition to defer its
execution, then the order of execution will be wrong:load A.js (A_code is defined)
A loads B.js (B_code is defined, not executed)
A then calls A_code() - oops, B code has not been executed yet.
B loads C.js (C_code is defined)
B_code() - oops, C code has not been executed yet.
C_code()
We need to reverse the order of execution, so C_code executes first,
followed by B_code, and finally A_code. To reverse the order of
execution, instead of a queue, we need a stack. If we have a global
variable called Code_stack, each file can push its own execution on the
stack when it is loaded, and write SCRIPT tags to load everything it
requires. Then at the top level after everything has been loaded, we
just evaluate everything on the Code_stack from top to bottom.So the order of execution becomes:
load A.js (push A_code)
load B.js (push B_code)
load C.js (push C_code)
C_code()
B_code()
A_code()
This algorithm should probably be modified to not execute a code block
if it has previously been executed. This could be implemented by having
each file set a file-specific global variable the first time it is
executed, and simply return if it has previously been set. e.g.if (A_executed) {
return;
}
A_executed = true;--
Daniel LaLiberte
[EMAIL PROTECTED]
http://www.HoloNexus.org/~liberte/
http://www.HyperNews.org/~liberte/_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-dev
Michael Pemberton
[EMAIL PROTECTED]
ICQ: 12107010