r70993 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70992‎ | r70993 | r70994 >
Date:21:02, 12 August 2010
Author:tparscal
Status:ok
Tags:
Comment:
Deferred executing callbacks given to mediaWiki.register by loader scripts until the dependency is actually needed.
Modified paths:
  • /branches/resourceloader/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js
@@ -158,7 +158,7 @@
159159 * Client-side module loader which integrates with the MediaWiki ResourceLoader
160160 */
161161 this.loader = new ( function() {
162 -
 162+
163163 /* Private Members */
164164
165165 var that = this;
@@ -168,7 +168,7 @@
169169 * Format:
170170 * {
171171 * 'moduleName': {
172 - * 'needs': ['required module', 'required module', ...],
 172+ * 'needs': ['required module', 'required module', ...], (or) function() {}
173173 * 'state': 'registered', 'loading', 'loaded', 'ready', or 'error'
174174 * 'script': function() {},
175175 * 'style': 'css code string',
@@ -193,6 +193,15 @@
194194 */
195195 function recurse( module, resolved, unresolved ) {
196196 unresolved[unresolved.length] = module;
 197+ // Resolves dynamic loader function and replaces it with it's own results
 198+ if ( typeof registry[module].needs === 'function' ) {
 199+ registry[module].needs = registry[module].needs();
 200+ // Gaurantees the module's needs are always in an array
 201+ if ( typeof registry[module].needs !== 'object' ) {
 202+ registry[module].needs = [registry[module].needs];
 203+ }
 204+ }
 205+ // Tracks down needs
197206 for ( var n = 0; n < registry[module].needs.length; n++ ) {
198207 if ( resolved.indexOf( registry[module].needs[n] ) === -1 ) {
199208 if ( unresolved.indexOf( registry[module].needs[n] ) !== -1 ) {
@@ -449,15 +458,11 @@
450459 }
451460 // List the module as registered
452461 registry[module] = { 'state': typeof status === 'string' ? status : 'registered', 'needs': [] };
453 - // Allow needs to be given as a function which returns a string or array
454 - if ( typeof needs === 'function' ) {
455 - needs = needs();
456 - }
457462 if ( typeof needs === 'string' ) {
458 - // Allow needs to be given as a single module module
 463+ // Allow needs to be given as a single module name
459464 registry[module].needs = [needs];
460 - } else if ( typeof needs === 'object' ) {
461 - // Allow needs to be given as an array of module modules
 465+ } else if ( typeof needs === 'object' || typeof needs === 'function' ) {
 466+ // Allow needs to be given as an array of module names or a function which returns an array
462467 registry[module].needs = needs;
463468 }
464469 };

Status & tagging log