r71603 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71602‎ | r71603 | r71604 >
Date:23:27, 24 August 2010
Author:tparscal
Status:ok
Tags:
Comment:
Changed the wording of "needs" to "dependencies"
Modified paths:
  • /branches/resourceloader/phase3/resources/mediawiki/mediawiki.js (modified) (history)

Diff [purge]

Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js
@@ -168,7 +168,7 @@
169169 * Format:
170170 * {
171171 * 'moduleName': {
172 - * 'needs': ['required module', 'required module', ...], (or) function() {}
 172+ * 'dependencies': ['required module', 'required module', ...], (or) function() {}
173173 * 'state': 'registered', 'loading', 'loaded', 'ready', or 'error'
174174 * 'script': function() {},
175175 * 'style': 'css code string',
@@ -194,29 +194,29 @@
195195 function recurse( module, resolved, unresolved ) {
196196 unresolved[unresolved.length] = module;
197197 // 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];
 198+ if ( typeof registry[module].dependencies === 'function' ) {
 199+ registry[module].dependencies = registry[module].dependencies();
 200+ // Gaurantees the module's dependencies are always in an array
 201+ if ( typeof registry[module].dependencies !== 'object' ) {
 202+ registry[module].dependencies = [registry[module].dependencies];
203203 }
204204 }
205 - // Tracks down needs
206 - for ( var n = 0; n < registry[module].needs.length; n++ ) {
207 - if ( resolved.indexOf( registry[module].needs[n] ) === -1 ) {
208 - if ( unresolved.indexOf( registry[module].needs[n] ) !== -1 ) {
 205+ // Tracks down dependencies
 206+ for ( var n = 0; n < registry[module].dependencies.length; n++ ) {
 207+ if ( resolved.indexOf( registry[module].dependencies[n] ) === -1 ) {
 208+ if ( unresolved.indexOf( registry[module].dependencies[n] ) !== -1 ) {
209209 throw new Error(
210 - 'Circular reference detected: ' + module + ' -> ' + registry[module].needs[n]
 210+ 'Circular reference detected: ' + module + ' -> ' + registry[module].dependencies[n]
211211 );
212212 }
213 - recurse( registry[module].needs[n], resolved, unresolved );
 213+ recurse( registry[module].dependencies[n], resolved, unresolved );
214214 }
215215 }
216216 resolved[resolved.length] = module;
217217 unresolved.splice( unresolved.indexOf( module ), 1 );
218218 }
219219 /**
220 - * Gets a list of modules names that a module needs in their proper dependency order
 220+ * Gets a list of modules names that a module dependencies in their proper dependency order
221221 *
222222 * @param mixed string module name or array of string module names
223223 * @return list of dependencies
@@ -227,14 +227,14 @@
228228 if ( typeof module === 'object' ) {
229229 var modules = [];
230230 for ( var m = 0; m < module.length; m++ ) {
231 - var needs = resolve( module[m] );
232 - for ( var n = 0; n < needs.length; n++ ) {
233 - modules[modules.length] = needs[n];
 231+ var dependencies = resolve( module[m] );
 232+ for ( var n = 0; n < dependencies.length; n++ ) {
 233+ modules[modules.length] = dependencies[n];
234234 }
235235 }
236236 return modules;
237237 } else if ( typeof module === 'string' ) {
238 - // Undefined modules have no needs
 238+ // Undefined modules have no dependencies
239239 if ( !( module in registry ) ) {
240240 return [];
241241 }
@@ -305,9 +305,9 @@
306306 try {
307307 registry[module].script();
308308 registry[module].state = 'ready';
309 - // Run jobs who's needs have just been met
 309+ // Run jobs who's dependencies have just been met
310310 for ( var j = 0; j < jobs.length; j++ ) {
311 - if ( filter( 'ready', jobs[j].needs ).compare( jobs[j].needs ) ) {
 311+ if ( filter( 'ready', jobs[j].dependencies ).compare( jobs[j].dependencies ) ) {
312312 if ( typeof jobs[j].ready === 'function' ) {
313313 jobs[j].ready();
314314 }
@@ -315,10 +315,10 @@
316316 j--;
317317 }
318318 }
319 - // Execute modules who's needs have just been met
 319+ // Execute modules who's dependencies have just been met
320320 for ( r in registry ) {
321321 if ( registry[r].state == 'loaded' ) {
322 - if ( filter( ['ready'], registry[r].needs ).compare( registry[r].needs ) ) {
 322+ if ( filter( ['ready'], registry[r].dependencies ).compare( registry[r].dependencies ) ) {
323323 execute( r );
324324 }
325325 }
@@ -329,7 +329,7 @@
330330 registry[module].state = 'error';
331331 // Run error callbacks of jobs affected by this condition
332332 for ( var j = 0; j < jobs.length; j++ ) {
333 - if ( jobs[j].needs.indexOf( module ) !== -1 ) {
 333+ if ( jobs[j].dependencies.indexOf( module ) !== -1 ) {
334334 if ( typeof jobs[j].error === 'function' ) {
335335 jobs[j].error();
336336 }
@@ -340,35 +340,35 @@
341341 }
342342 }
343343 /**
344 - * Adds a needs to the queue with optional callbacks to be run when the needs are ready or fail
 344+ * Adds a dependencies to the queue with optional callbacks to be run when the dependencies are ready or fail
345345 *
346346 * @param mixed string moulde name or array of string module names
347 - * @param function ready callback to execute when all needs are ready
348 - * @param function error callback to execute when any need fails
 347+ * @param function ready callback to execute when all dependencies are ready
 348+ * @param function error callback to execute when any dependency fails
349349 */
350 - function request( needs, ready, error ) {
 350+ function request( dependencies, ready, error ) {
351351 // Allow calling by single module name
352 - if ( typeof needs === 'string' ) {
353 - needs = [needs];
354 - if ( needs[0] in registry ) {
355 - for ( var n = 0; n < registry[needs[0]].needs.length; n++ ) {
356 - needs[needs.length] = registry[needs[0]].needs[n];
 352+ if ( typeof dependencies === 'string' ) {
 353+ dependencies = [dependencies];
 354+ if ( dependencies[0] in registry ) {
 355+ for ( var n = 0; n < registry[dependencies[0]].dependencies.length; n++ ) {
 356+ dependencies[dependencies.length] = registry[dependencies[0]].dependencies[n];
357357 }
358358 }
359359 }
360360 // Add ready and error callbacks if they were given
361361 if ( arguments.length > 1 ) {
362362 jobs[jobs.length] = {
363 - 'needs': filter( ['undefined', 'registered', 'loading', 'loaded'], needs ),
 363+ 'dependencies': filter( ['undefined', 'registered', 'loading', 'loaded'], dependencies ),
364364 'ready': ready,
365365 'error': error
366366 };
367367 }
368 - // Queue up any needs that are undefined or registered
369 - needs = filter( ['undefined', 'registered'], needs );
370 - for ( var n = 0; n < needs.length; n++ ) {
371 - if ( queue.indexOf( needs[n] ) === -1 ) {
372 - queue[queue.length] = needs[n];
 368+ // Queue up any dependencies that are undefined or registered
 369+ dependencies = filter( ['undefined', 'registered'], dependencies );
 370+ for ( var n = 0; n < dependencies.length; n++ ) {
 371+ if ( queue.indexOf( dependencies[n] ) === -1 ) {
 372+ queue[queue.length] = dependencies[n];
373373 }
374374 }
375375 // Work the queue
@@ -378,7 +378,7 @@
379379 /* Public Methods */
380380
381381 /**
382 - * Requests needs from server, loading and executing when things when ready.
 382+ * Requests dependencies from server, loading and executing when things when ready.
383383 */
384384 this.work = function() {
385385 // Appends a list of modules to the batch
@@ -438,7 +438,7 @@
439439 * Registers a module, letting the system know about it and it's dependencies. loader.js files contain calls
440440 * to this function.
441441 */
442 - this.register = function( module, needs, status ) {
 442+ this.register = function( module, dependencies, status ) {
443443 // Allow multiple registration
444444 if ( typeof module === 'object' ) {
445445 for ( var n = 0; n < module.length; n++ ) {
@@ -458,13 +458,13 @@
459459 throw new Error( 'module already implemeneted: ' + module );
460460 }
461461 // List the module as registered
462 - registry[module] = { 'state': typeof status === 'string' ? status : 'registered', 'needs': [] };
463 - if ( typeof needs === 'string' ) {
464 - // Allow needs to be given as a single module name
465 - registry[module].needs = [needs];
466 - } else if ( typeof needs === 'object' || typeof needs === 'function' ) {
467 - // Allow needs to be given as an array of module names or a function which returns an array
468 - registry[module].needs = needs;
 462+ registry[module] = { 'state': typeof status === 'string' ? status : 'registered', 'dependencies': [] };
 463+ if ( typeof dependencies === 'string' ) {
 464+ // Allow dependencies to be given as a single module name
 465+ registry[module].dependencies = [dependencies];
 466+ } else if ( typeof dependencies === 'object' || typeof dependencies === 'function' ) {
 467+ // Allow dependencies to be given as an array of module names or a function which returns an array
 468+ registry[module].dependencies = dependencies;
469469 }
470470 };
471471 /**
@@ -500,7 +500,7 @@
501501 registry[module].messages = localization;
502502 }
503503 // Execute or queue callback
504 - if ( filter( ['ready'], registry[module].needs ).compare( registry[module].needs ) ) {
 504+ if ( filter( ['ready'], registry[module].dependencies ).compare( registry[module].dependencies ) ) {
505505 execute( module );
506506 } else {
507507 request( module );
@@ -509,36 +509,37 @@
510510 /**
511511 * Executes a function as soon as one or more required modules are ready
512512 *
513 - * @param mixed string or array of strings of modules names the callback needs to be ready before executing
514 - * @param function callback to execute when all needs are ready (optional)
515 - * @param function callback to execute when if needs have a errors (optional)
 513+ * @param mixed string or array of strings of modules names the callback dependencies to be ready before
 514+ * executing
 515+ * @param function callback to execute when all dependencies are ready (optional)
 516+ * @param function callback to execute when if dependencies have a errors (optional)
516517 */
517 - this.using = function( needs, ready, error ) {
 518+ this.using = function( dependencies, ready, error ) {
518519 // Validate input
519 - if ( typeof needs !== 'object' && typeof needs !== 'string' ) {
520 - throw new Error( 'needs must be a string or an array, not a ' + typeof needs )
 520+ if ( typeof dependencies !== 'object' && typeof dependencies !== 'string' ) {
 521+ throw new Error( 'dependencies must be a string or an array, not a ' + typeof dependencies )
521522 }
522 - // Allow calling with a single need as a string
523 - if ( typeof needs === 'string' ) {
524 - needs = [needs];
 523+ // Allow calling with a single dependency as a string
 524+ if ( typeof dependencies === 'string' ) {
 525+ dependencies = [dependencies];
525526 }
526527 // Resolve entire dependency map
527 - needs = resolve( needs );
528 - // If all needs are met, execute ready immediately
529 - if ( filter( ['ready'], needs ).compare( needs ) ) {
 528+ dependencies = resolve( dependencies );
 529+ // If all dependencies are met, execute ready immediately
 530+ if ( filter( ['ready'], dependencies ).compare( dependencies ) ) {
530531 if ( typeof ready !== 'function' ) {
531532 ready();
532533 }
533534 }
534 - // If any needs have errors execute error immediately
535 - else if ( filter( ['error'], needs ).length ) {
 535+ // If any dependencies have errors execute error immediately
 536+ else if ( filter( ['error'], dependencies ).length ) {
536537 if ( typeof error === 'function' ) {
537538 error();
538539 }
539540 }
540 - // Since some needs are not yet ready, queue up a request
 541+ // Since some dependencies are not yet ready, queue up a request
541542 else {
542 - request( needs, ready, error );
 543+ request( dependencies, ready, error );
543544 }
544545 };
545546 /**
@@ -547,15 +548,15 @@
548549 this.load = function( modules ) {
549550 // Validate input
550551 if ( typeof modules !== 'object' && typeof modules !== 'string' ) {
551 - throw new Error( 'needs must be a string or an array, not a ' + typeof needs )
 552+ throw new Error( 'dependencies must be a string or an array, not a ' + typeof dependencies )
552553 }
553 - // Allow calling with a single need as a string
 554+ // Allow calling with a single dependency as a string
554555 if ( typeof modules === 'string' ) {
555556 modules = [modules];
556557 }
557558 // Resolve entire dependency map
558559 modules = resolve( modules );
559 - // If all modules are ready, nothing need be done
 560+ // If all modules are ready, nothing dependency be done
560561 if ( filter( ['ready'], modules ).compare( modules ) ) {
561562 return true;
562563 }

Status & tagging log