Skip to content

Commit 023e4bb

Browse files
committed
fix: check for config names when needed
Fixes #214 Fixes #198
1 parent e1a3043 commit 023e4bb

14 files changed

+286
-226
lines changed

dist/modules/ocLazyLoad.core.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@
170170
if (!moduleName || justLoaded.indexOf(moduleName) !== -1) {
171171
continue;
172172
}
173-
var newModule = regModules.indexOf(moduleName) === -1;
173+
// new if not registered, and not a config name
174+
var newModule = regModules.indexOf(moduleName) === -1 && !modules[moduleName];
174175
moduleFn = ngModuleFct(moduleName);
175176
if (newModule) {
176177
// new module
@@ -281,10 +282,10 @@
281282
} else {
282283
// config block
283284
var callInvoke = function callInvoke(fct) {
284-
var invoked = regConfigs.indexOf('' + moduleName + '-' + fct);
285+
var invoked = regConfigs.indexOf(moduleName + '-' + fct);
285286
if (invoked === -1 || reconfig) {
286287
if (invoked === -1) {
287-
regConfigs.push('' + moduleName + '-' + fct);
288+
regConfigs.push(moduleName + '-' + fct);
288289
}
289290
if (angular.isDefined(provider)) {
290291
provider[args[1]].apply(provider, args[2]);
@@ -519,6 +520,8 @@
519520
return;
520521
}
521522
requireEntry = config;
523+
// ignore the name because it's probably not a real module name
524+
config.name = undefined;
522525
}
523526

524527
// Check if this dependency has been loaded previously
@@ -544,9 +547,21 @@
544547
}
545548
return;
546549
} else if (angular.isArray(requireEntry)) {
547-
requireEntry = {
548-
files: requireEntry
549-
};
550+
var files = [];
551+
angular.forEach(requireEntry, function (entry) {
552+
// let's check if the entry is a file name or a config name
553+
var config = self.getModuleConfig(entry);
554+
if (config === null) {
555+
files.push(entry);
556+
} else if (config.files) {
557+
files = files.concat(config.files);
558+
}
559+
});
560+
if (files.length > 0) {
561+
requireEntry = {
562+
files: files
563+
};
564+
}
550565
} else if (angular.isObject(requireEntry)) {
551566
if (requireEntry.hasOwnProperty('name') && requireEntry['name']) {
552567
// The dependency doesn't exist in the module cache and is a new configuration, so store and push it.
@@ -578,7 +593,7 @@
578593
* @param localParams
579594
*/
580595
inject: function inject(moduleName) {
581-
var localParams = arguments[1] === undefined ? {} : arguments[1];
596+
var localParams = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
582597

583598
var self = this,
584599
deferred = $q.defer();
@@ -610,8 +625,8 @@
610625
if (modulesToLoad.length > 0) {
611626
loadNext(modulesToLoad.shift()); // load the next in list
612627
} else {
613-
deferred.resolve(res); // everything has been loaded, resolve
614-
}
628+
deferred.resolve(res); // everything has been loaded, resolve
629+
}
615630
}, function error(err) {
616631
deferred.reject(err);
617632
});

dist/modules/ocLazyLoad.loaders.common.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@
2323
var dc = new Date().getTime();
2424
if (url.indexOf('?') >= 0) {
2525
if (url.substring(0, url.length - 1) === '&') {
26-
return '' + url + '_dc=' + dc;
26+
return url + '_dc=' + dc;
2727
}
28-
return '' + url + '&_dc=' + dc;
28+
return url + '&_dc=' + dc;
2929
} else {
30-
return '' + url + '?_dc=' + dc;
30+
return url + '?_dc=' + dc;
3131
}
3232
};
3333

@@ -92,9 +92,9 @@
9292
var v = $window.navigator.appVersion.match(/OS (\d+)_(\d+)_?(\d+)?/);
9393
var iOSVersion = parseFloat([parseInt(v[1], 10), parseInt(v[2], 10), parseInt(v[3] || 0, 10)].join('.'));
9494
useCssLoadPatch = iOSVersion < 6;
95-
} else if (ua.indexOf('android') > -1) {
95+
} else if (ua.indexOf("android") > -1) {
9696
// Android < 4.4
97-
var androidVersion = parseFloat(ua.slice(ua.indexOf('android') + 8));
97+
var androidVersion = parseFloat(ua.slice(ua.indexOf("android") + 8));
9898
useCssLoadPatch = androidVersion < 4.4;
9999
} else if (ua.indexOf('safari') > -1) {
100100
var versionMatch = ua.match(/version\/([\.\d]+)/i);

dist/modules/ocLazyLoad.loaders.core.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* @returns {*}
1111
*/
1212
$delegate.filesLoader = function filesLoader(config) {
13-
var params = arguments[1] === undefined ? {} : arguments[1];
13+
var params = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
1414

1515
var cssFiles = [],
1616
templatesFiles = [],
@@ -116,7 +116,7 @@
116116

117117
if (promises.length === 0) {
118118
var deferred = $q.defer(),
119-
err = 'Error: no file to load has been found, if you\'re trying to load an existing module you should use the \'inject\' method instead of \'load\'.';
119+
err = "Error: no file to load has been found, if you're trying to load an existing module you should use the 'inject' method instead of 'load'.";
120120
$delegate._$log.error(err);
121121
deferred.reject(err);
122122
return deferred.promise;
@@ -139,7 +139,7 @@
139139
* @returns promise
140140
*/
141141
$delegate.load = function (originalModule) {
142-
var originalParams = arguments[1] === undefined ? {} : arguments[1];
142+
var originalParams = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
143143

144144
var self = this,
145145
config = null,
+60-60
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,63 @@
11
// Array.indexOf polyfill for IE8
22
if (!Array.prototype.indexOf) {
3-
Array.prototype.indexOf = function (searchElement, fromIndex) {
4-
var k;
5-
6-
// 1. Let O be the result of calling ToObject passing
7-
// the this value as the argument.
8-
if (this == null) {
9-
throw new TypeError('"this" is null or not defined');
10-
}
11-
12-
var O = Object(this);
13-
14-
// 2. Let lenValue be the result of calling the Get
15-
// internal method of O with the argument "length".
16-
// 3. Let len be ToUint32(lenValue).
17-
var len = O.length >>> 0;
18-
19-
// 4. If len is 0, return -1.
20-
if (len === 0) {
21-
return -1;
22-
}
23-
24-
// 5. If argument fromIndex was passed let n be
25-
// ToInteger(fromIndex); else let n be 0.
26-
var n = +fromIndex || 0;
27-
28-
if (Math.abs(n) === Infinity) {
29-
n = 0;
30-
}
31-
32-
// 6. If n >= len, return -1.
33-
if (n >= len) {
34-
return -1;
35-
}
36-
37-
// 7. If n >= 0, then Let k be n.
38-
// 8. Else, n<0, Let k be len - abs(n).
39-
// If k is less than 0, then let k be 0.
40-
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
41-
42-
// 9. Repeat, while k < len
43-
while (k < len) {
44-
// a. Let Pk be ToString(k).
45-
// This is implicit for LHS operands of the in operator
46-
// b. Let kPresent be the result of calling the
47-
// HasProperty internal method of O with argument Pk.
48-
// This step can be combined with c
49-
// c. If kPresent is true, then
50-
// i. Let elementK be the result of calling the Get
51-
// internal method of O with the argument ToString(k).
52-
// ii. Let same be the result of applying the
53-
// Strict Equality Comparison Algorithm to
54-
// searchElement and elementK.
55-
// iii. If same is true, return k.
56-
if (k in O && O[k] === searchElement) {
57-
return k;
58-
}
59-
k++;
60-
}
61-
return -1;
62-
};
3+
Array.prototype.indexOf = function (searchElement, fromIndex) {
4+
var k;
5+
6+
// 1. Let O be the result of calling ToObject passing
7+
// the this value as the argument.
8+
if (this == null) {
9+
throw new TypeError('"this" is null or not defined');
10+
}
11+
12+
var O = Object(this);
13+
14+
// 2. Let lenValue be the result of calling the Get
15+
// internal method of O with the argument "length".
16+
// 3. Let len be ToUint32(lenValue).
17+
var len = O.length >>> 0;
18+
19+
// 4. If len is 0, return -1.
20+
if (len === 0) {
21+
return -1;
22+
}
23+
24+
// 5. If argument fromIndex was passed let n be
25+
// ToInteger(fromIndex); else let n be 0.
26+
var n = +fromIndex || 0;
27+
28+
if (Math.abs(n) === Infinity) {
29+
n = 0;
30+
}
31+
32+
// 6. If n >= len, return -1.
33+
if (n >= len) {
34+
return -1;
35+
}
36+
37+
// 7. If n >= 0, then Let k be n.
38+
// 8. Else, n<0, Let k be len - abs(n).
39+
// If k is less than 0, then let k be 0.
40+
k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
41+
42+
// 9. Repeat, while k < len
43+
while (k < len) {
44+
// a. Let Pk be ToString(k).
45+
// This is implicit for LHS operands of the in operator
46+
// b. Let kPresent be the result of calling the
47+
// HasProperty internal method of O with argument Pk.
48+
// This step can be combined with c
49+
// c. If kPresent is true, then
50+
// i. Let elementK be the result of calling the Get
51+
// internal method of O with the argument ToString(k).
52+
// ii. Let same be the result of applying the
53+
// Strict Equality Comparison Algorithm to
54+
// searchElement and elementK.
55+
// iii. If same is true, return k.
56+
if (k in O && O[k] === searchElement) {
57+
return k;
58+
}
59+
k++;
60+
}
61+
return -1;
62+
};
6363
}

0 commit comments

Comments
 (0)