Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I use the loader a lot. It's a great way to manage dependencies and build you library around.</p> <p>I've run into 3 problems with it:</p> <ol> <li>Debugging - it's difficult to debug. Is the bug in the module's loader definition or is it in the module (script file)?</li> <li>You have to add your own 'subscibeOnce' function to add any 'on module(s) loaded' handlers. This unsubscribes your handlers after the module has been loaded/inserted into the page. Otherwise, if you insert more modules later in the page's lifespan - they called each time.</li> <li>There's a limit to what dependencies it can figure out. Ordering within the requires:[] (in the module definition) seems to matter. I've seen it fail trying to work through this list.</li> </ol> <p>What i use is something like:</p> <pre><code>var TheBase = function(oConfig){ var thisBase = this; var EVENTS = { ON_SCRIPTS_LOADED : "onScriptsLoaded" , ON_SCRIPTS_PROGRESS : "onScriptsProgress" } for(var eventName in EVENTS){ thisBase.createEvent(EVENTS[eventName]); } var _loader = new YAHOO.util.YUILoader({ base: oConfig.yuiBasePath ,onSuccess:function(o){ thisBase.fireEvent(EVENTS.ON_SCRIPTS_LOADED); } ,onProgress:function(o){ thisBase.fireEvent(EVENTS.ON_SCRIPTS_PROGRESS,o.name); } }) //optional thisBase.loader = _loader; </code></pre> <p>}</p> <pre><code>TheBase.prototype = { subscribeOnce : function(eventName, fnc, context, args){ var that = this; var handler = function hander(){ fnc.apply(context, arguments); that.unsubscribe(eventName, handler); } this.subscribe(eventName, handler, args, false); } </code></pre> <p>}</p> <p>//augment with event provider</p> <pre><code>YAHOO.lang.augment(TheBase, YAHOO.util.EventProvider); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload