Simon Tiffert told us of a co-workers post on loading your JavaScript modules with the YUI Loader.

The post discusses how you can use the loader for your own libraries, giving you full dependency management, similar to that of the Dojo loader and others:

As YUI comes with a special module for loading dependencies, the YUI Loader Utility, we explored if we could use YUI for our needs. The Loader’s feature list reads like our wish-list:

  • Reliable, sorted loading of dependencies
  • Safe, efficient mechanism for adding new components to a page on which YUI may already be present.
  • Automatic use of rolled-up files.

So we’ve developed our own solution on top of the YUI loader for our Framework. It consists of two components: A Compile-time dependency analyzer and a configuration file generated by the dependency analyzer that tells YUI how to load our modules.

Then we get to see the details on how you take this API:

JAVASCRIPT:

  1.  
  2. var loader = agimatec_config.getLoader()
  3. loader.require(“agimatec.topic”);
  4. loader.insert(function(){
  5.         // use agimatec.topic and ALL of its dependencies here !!!!
  6. });
  7.  

and have it walk the stack, including the way to annotate your module:

JAVASCRIPT:

  1.  
  2. // @@module agimatec.topic
  3. // @@requires event, agimatec.datatypes
  4.  
  5. // Module code goes here
  6. // …
  7.  
  8. // Tell the loader that this module has been loaded
  9. YAHOO.register(“agimatec.topic”, agimatec.topic, {version:‘1.0′,build:‘000′});
  10.  

Source: Ajaxian » Front Page
Original Article: http://feeds.feedburner.com/~r/ajaxian/~3/520825557/yui-loader

Comments are closed.



Site Navigation