Hi!
Can a JavaScript / ResourceLoader guru explain what's wrong with my code?

Module definitions at server side:
http://pastebin.com/8cmRbNxe

modules are loaded correctly by the following code:
http://pastebin.com/MFWk6znv
It is checked many times during extension development, 'localBasePath' and 'remoteExtPath' is set up correctly.

* By default, the module with the following code is loaded:
http://pastebin.com/0u96aMep

Then it loads either 'ext.jqgmap.view' module or 'ext.jqgmap.edit' module, depending on data provided in generated html page.

This is made for two reasons:
1. Editor code is larger and when the page does not need the editor, it loads only viewer code, which is faster to load.
2. Editor modifies the mw.jqgmap.MapController.prototype.createEditor
and in the future may also introduce or modify more prototypes. This makes code more modular.

However, I have very big problem loading 'ext.jqgmap.view' from 'ext.jqgmap.edit':

1.
   mw.loader.using( 'ext.jqgmap.view', function() {
2.
   console.log(mw.jqgmap);

When callback function is executed, Chrome console does not show mw.jqgmap as being defined. So console.log(mw.jqgmap) returns 'undefined' and only when that happens, actual execution of 'ext.jqgmap.view' begins. It seems that ResourceLoader loads the code wrapped into exception handler which tries to detect when the code has to be loaded. That would be ok, however, when I execute 'ext.jqgmap.view' code step by step:

1.
   if ( mw.jqgmap ) {
2.
   return;
3.
   }
4.
5.
   mw.jqgmap = (function () {

First line
if ( mw.jqgmap ) {
}

is executed second time, when mw.jqgmap value is set with closure result. Then the further execution of code just stops. No further errors in Chrome console. And, even mw.jqgmap is correctly defined!

There used to be no if (mw.jqgmap) ( return; ) check originally, then another code (Google maps) complained about being included twice, which may cause "unpredictable results".

How can I fix the chain of loading so it will correctly setup mw.jqgmap.MapController and mw.jqgmap.MarkerController so they will be different in edit and view mode and available to use in 'ext,jqgmap' code?

I also have the whole extension under development however I haven't comitted it into svn yet - I don't know whether yet another map extension is desirable there. Although there was no rule against duplicate functionality in extensions?

ResourceLoader is a bit hard to me.

Dmitriy

_______________________________________________
Wikitech-l mailing list
Wikitech-l@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/wikitech-l

Reply via email to