4
4
* @author Maximilian Beck
5
5
* @link http://glumb.de/loomjs
6
6
* @license http://opensource.org/licenses/MIT
7
- * @version 0.1 .0
7
+ * @version 0.2 .0
8
8
*/
9
9
10
- module = ( function ( ) {
10
+ ( function ( namespace ) {
11
11
var debug = false ,
12
12
13
13
moduleContainer = { } ,
14
- waitingFor = { } , //'a':['b','c'] module b,c are waiting for a
14
+ moduleQueue = { } , //'a':['b','c'] module b,c are waiting for a
15
15
requireId = 0 ;
16
16
17
17
function define ( moduleName , deps , module , resolve ) { //('n',[d],m,r) ('n',m,r) ('n',[d],m) ('n',m)
@@ -36,7 +36,7 @@ module = (function () {
36
36
resolved : false
37
37
} ;
38
38
39
- if ( waitingFor [ moduleName ] || resolve ) {
39
+ if ( moduleQueue [ moduleName ] || resolve ) {
40
40
resolveModuleDeps ( moduleName ) ;
41
41
}
42
42
}
@@ -50,28 +50,32 @@ module = (function () {
50
50
// adds moduleName to the list of the module it is waiting for
51
51
function addWaitingFor ( moduleName , waitingForName ) {
52
52
log ( 'module "' + moduleName + '" waiting for module "' + waitingForName + '"' ) ;
53
- var pendingEntry = waitingFor [ waitingForName ] || [ ] ; //['a','b'] or []
53
+ var pendingEntry = moduleQueue [ waitingForName ] || [ ] ; //['a','b'] or []
54
54
55
55
if ( ! ( pendingEntry . indexOf ( moduleName ) > - 1 ) ) {
56
56
pendingEntry . push ( moduleName ) ;
57
- waitingFor [ waitingForName ] = pendingEntry ;
57
+ moduleQueue [ waitingForName ] = pendingEntry ;
58
58
}
59
59
}
60
60
61
61
function removeWaitingFor ( moduleName ) {
62
- log ( 'deleting waitingFor : "' + moduleName + '"' ) ;
63
- delete waitingFor [ moduleName ] ;
62
+ log ( 'deleting moduleQueue : "' + moduleName + '"' ) ;
63
+ delete moduleQueue [ moduleName ] ;
64
64
}
65
65
66
66
function resolveModule ( moduleName , deps ) {
67
67
68
68
var module = moduleContainer [ moduleName ] ;
69
69
70
70
module . resolved = true ;
71
- module . module = ( deps !== undefined && deps . length > 0 ) ? module . module . apply ( this , deps ) : module . module . apply ( this ) ;
72
-
73
- if ( waitingFor [ moduleName ] ) {
74
- var waitingForArr = waitingFor [ moduleName ] ; //['b','c'] b, c waiting for module
71
+ module . module = ( typeof module . module !== 'function' ) ?
72
+ module . module :
73
+ ( deps !== undefined && deps . length > 0 ) ?
74
+ module . module . apply ( null , deps ) :
75
+ module . module . apply ( null ) ;
76
+
77
+ if ( moduleQueue [ moduleName ] ) {
78
+ var waitingForArr = moduleQueue [ moduleName ] ; //['b','c'] b, c waiting for module
75
79
for ( var i = 0 ; i < waitingForArr . length ; i ++ ) {
76
80
resolveModuleDeps ( waitingForArr [ i ] ) ;
77
81
}
@@ -127,9 +131,16 @@ module = (function () {
127
131
console . log ( message ) ;
128
132
}
129
133
130
- return {
131
- "debug" : setDebug ,
132
- "require" : require ,
133
- "define" : define
134
- }
135
- } ) ( ) ;
134
+ namespace . define = define ;
135
+ namespace . require = require ;
136
+
137
+ namespace . define . amd = true ;
138
+
139
+ namespace . loom = {
140
+ "queue" : moduleQueue ,
141
+ "modules" : moduleContainer ,
142
+ "requireCounter" : requireId ,
143
+ "debug" : setDebug
144
+ } ;
145
+
146
+ } ) ( window ) ;
0 commit comments