Index: branches/resourceloader/phase3/resources/mediawiki/mediawiki.js |
— | — | @@ -168,7 +168,7 @@ |
169 | 169 | * Format: |
170 | 170 | * { |
171 | 171 | * 'moduleName': { |
172 | | - * 'needs': ['required module', 'required module', ...], (or) function() {} |
| 172 | + * 'dependencies': ['required module', 'required module', ...], (or) function() {} |
173 | 173 | * 'state': 'registered', 'loading', 'loaded', 'ready', or 'error' |
174 | 174 | * 'script': function() {}, |
175 | 175 | * 'style': 'css code string', |
— | — | @@ -194,29 +194,29 @@ |
195 | 195 | function recurse( module, resolved, unresolved ) { |
196 | 196 | unresolved[unresolved.length] = module; |
197 | 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]; |
| 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]; |
203 | 203 | } |
204 | 204 | } |
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 ) { |
209 | 209 | throw new Error( |
210 | | - 'Circular reference detected: ' + module + ' -> ' + registry[module].needs[n] |
| 210 | + 'Circular reference detected: ' + module + ' -> ' + registry[module].dependencies[n] |
211 | 211 | ); |
212 | 212 | } |
213 | | - recurse( registry[module].needs[n], resolved, unresolved ); |
| 213 | + recurse( registry[module].dependencies[n], resolved, unresolved ); |
214 | 214 | } |
215 | 215 | } |
216 | 216 | resolved[resolved.length] = module; |
217 | 217 | unresolved.splice( unresolved.indexOf( module ), 1 ); |
218 | 218 | } |
219 | 219 | /** |
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 |
221 | 221 | * |
222 | 222 | * @param mixed string module name or array of string module names |
223 | 223 | * @return list of dependencies |
— | — | @@ -227,14 +227,14 @@ |
228 | 228 | if ( typeof module === 'object' ) { |
229 | 229 | var modules = []; |
230 | 230 | 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]; |
234 | 234 | } |
235 | 235 | } |
236 | 236 | return modules; |
237 | 237 | } else if ( typeof module === 'string' ) { |
238 | | - // Undefined modules have no needs |
| 238 | + // Undefined modules have no dependencies |
239 | 239 | if ( !( module in registry ) ) { |
240 | 240 | return []; |
241 | 241 | } |
— | — | @@ -305,9 +305,9 @@ |
306 | 306 | try { |
307 | 307 | registry[module].script(); |
308 | 308 | registry[module].state = 'ready'; |
309 | | - // Run jobs who's needs have just been met |
| 309 | + // Run jobs who's dependencies have just been met |
310 | 310 | 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 ) ) { |
312 | 312 | if ( typeof jobs[j].ready === 'function' ) { |
313 | 313 | jobs[j].ready(); |
314 | 314 | } |
— | — | @@ -315,10 +315,10 @@ |
316 | 316 | j--; |
317 | 317 | } |
318 | 318 | } |
319 | | - // Execute modules who's needs have just been met |
| 319 | + // Execute modules who's dependencies have just been met |
320 | 320 | for ( r in registry ) { |
321 | 321 | 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 ) ) { |
323 | 323 | execute( r ); |
324 | 324 | } |
325 | 325 | } |
— | — | @@ -329,7 +329,7 @@ |
330 | 330 | registry[module].state = 'error'; |
331 | 331 | // Run error callbacks of jobs affected by this condition |
332 | 332 | for ( var j = 0; j < jobs.length; j++ ) { |
333 | | - if ( jobs[j].needs.indexOf( module ) !== -1 ) { |
| 333 | + if ( jobs[j].dependencies.indexOf( module ) !== -1 ) { |
334 | 334 | if ( typeof jobs[j].error === 'function' ) { |
335 | 335 | jobs[j].error(); |
336 | 336 | } |
— | — | @@ -340,35 +340,35 @@ |
341 | 341 | } |
342 | 342 | } |
343 | 343 | /** |
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 |
345 | 345 | * |
346 | 346 | * @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 |
349 | 349 | */ |
350 | | - function request( needs, ready, error ) { |
| 350 | + function request( dependencies, ready, error ) { |
351 | 351 | // 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]; |
357 | 357 | } |
358 | 358 | } |
359 | 359 | } |
360 | 360 | // Add ready and error callbacks if they were given |
361 | 361 | if ( arguments.length > 1 ) { |
362 | 362 | jobs[jobs.length] = { |
363 | | - 'needs': filter( ['undefined', 'registered', 'loading', 'loaded'], needs ), |
| 363 | + 'dependencies': filter( ['undefined', 'registered', 'loading', 'loaded'], dependencies ), |
364 | 364 | 'ready': ready, |
365 | 365 | 'error': error |
366 | 366 | }; |
367 | 367 | } |
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]; |
373 | 373 | } |
374 | 374 | } |
375 | 375 | // Work the queue |
— | — | @@ -378,7 +378,7 @@ |
379 | 379 | /* Public Methods */ |
380 | 380 | |
381 | 381 | /** |
382 | | - * Requests needs from server, loading and executing when things when ready. |
| 382 | + * Requests dependencies from server, loading and executing when things when ready. |
383 | 383 | */ |
384 | 384 | this.work = function() { |
385 | 385 | // Appends a list of modules to the batch |
— | — | @@ -438,7 +438,7 @@ |
439 | 439 | * Registers a module, letting the system know about it and it's dependencies. loader.js files contain calls |
440 | 440 | * to this function. |
441 | 441 | */ |
442 | | - this.register = function( module, needs, status ) { |
| 442 | + this.register = function( module, dependencies, status ) { |
443 | 443 | // Allow multiple registration |
444 | 444 | if ( typeof module === 'object' ) { |
445 | 445 | for ( var n = 0; n < module.length; n++ ) { |
— | — | @@ -458,13 +458,13 @@ |
459 | 459 | throw new Error( 'module already implemeneted: ' + module ); |
460 | 460 | } |
461 | 461 | // 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; |
469 | 469 | } |
470 | 470 | }; |
471 | 471 | /** |
— | — | @@ -500,7 +500,7 @@ |
501 | 501 | registry[module].messages = localization; |
502 | 502 | } |
503 | 503 | // 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 ) ) { |
505 | 505 | execute( module ); |
506 | 506 | } else { |
507 | 507 | request( module ); |
— | — | @@ -509,36 +509,37 @@ |
510 | 510 | /** |
511 | 511 | * Executes a function as soon as one or more required modules are ready |
512 | 512 | * |
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) |
516 | 517 | */ |
517 | | - this.using = function( needs, ready, error ) { |
| 518 | + this.using = function( dependencies, ready, error ) { |
518 | 519 | // 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 ) |
521 | 522 | } |
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]; |
525 | 526 | } |
526 | 527 | // 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 ) ) { |
530 | 531 | if ( typeof ready !== 'function' ) { |
531 | 532 | ready(); |
532 | 533 | } |
533 | 534 | } |
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 ) { |
536 | 537 | if ( typeof error === 'function' ) { |
537 | 538 | error(); |
538 | 539 | } |
539 | 540 | } |
540 | | - // Since some needs are not yet ready, queue up a request |
| 541 | + // Since some dependencies are not yet ready, queue up a request |
541 | 542 | else { |
542 | | - request( needs, ready, error ); |
| 543 | + request( dependencies, ready, error ); |
543 | 544 | } |
544 | 545 | }; |
545 | 546 | /** |
— | — | @@ -547,15 +548,15 @@ |
548 | 549 | this.load = function( modules ) { |
549 | 550 | // Validate input |
550 | 551 | 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 ) |
552 | 553 | } |
553 | | - // Allow calling with a single need as a string |
| 554 | + // Allow calling with a single dependency as a string |
554 | 555 | if ( typeof modules === 'string' ) { |
555 | 556 | modules = [modules]; |
556 | 557 | } |
557 | 558 | // Resolve entire dependency map |
558 | 559 | modules = resolve( modules ); |
559 | | - // If all modules are ready, nothing need be done |
| 560 | + // If all modules are ready, nothing dependency be done |
560 | 561 | if ( filter( ['ready'], modules ).compare( modules ) ) { |
561 | 562 | return true; |
562 | 563 | } |