Skip to content

Commit

Permalink
chore: bump to 0.3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
ocombe committed Jul 23, 2014
1 parent e2fec59 commit 3dab3fe
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 58 deletions.
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
<a name="0.3.3"></a>
# 0.3.3 (2014-07-23)


## Bug Fixes

- don't execute config blocks multiple times by default
([e2fec59e](https://github.com/ocombe/ocLazyLoad/commit/e2fec59ee7ff1e95e7e78ef8397c4fe500d8e7c0),
[#43](https://github.com/ocombe/ocLazyLoad/issues/43), [#41](https://github.com/ocombe/ocLazyLoad/issues/41))
- don't test for .js in path because of requirejs
([6045214b](https://github.com/ocombe/ocLazyLoad/commit/6045214b6a4cc2d9dee1c1f2f89946687d963828))
- test order
([8412cb43](https://github.com/ocombe/ocLazyLoad/commit/8412cb431bfc742f2c4151e5b089f3313a70035e))


<a name="0.3.2"></a>
# 0.3.2 (2014-07-23)

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ocLazyLoad",
"version": "0.3.2",
"version": "0.3.3",
"description": "Load modules on demand (lazy load) with angularJS",
"main": "dist/ocLazyLoad.min.js",
"homepage": "https://github.com/ocombe/ocLazyLoad",
Expand Down
45 changes: 27 additions & 18 deletions dist/ocLazyLoad.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* ocLazyLoad - Load modules on demand (lazy load) with angularJS
* @version v0.3.1
* @version v0.3.2
* @link https://github.com/ocombe/ocLazyLoad
* @license MIT
* @author Olivier Combe <olivier.combe@gmail.com>
Expand All @@ -9,6 +9,7 @@
'use strict';
var regModules = ['ng'],
regInvokes = [],
regConfigs = [],
ocLazyLoad = angular.module('oc.lazyLoad', ['ng']),
broadcast = angular.noop;

Expand Down Expand Up @@ -196,19 +197,21 @@
templatesLoader.ocLazyLoadLoader = true;
}

var filesLoader = function(paths, params) {
var filesLoader = function(config, params) {
var cssFiles = [],
templatesFiles = [],
jsFiles = [],
promises = [];

angular.forEach(paths, function(path) {
angular.extend(params || {}, config);

angular.forEach(params.files, function(path) {
if(angular.isUndefined(filesCache.get(path)) || params.cache === false) {
if(/\.css[^\.]*$/.test(path) && cssFiles.indexOf(path) === -1) {
cssFiles.push(path);
} else if(/\.(htm|html)[^\.]*$/.test(path) && templatesFiles.indexOf(path) === -1) {
templatesFiles.push(path);
} else if (/\.(js)[^\.]*$/.test(path) && jsFiles.indexOf(path) === -1) {
} else if (jsFiles.indexOf(path) === -1) {
jsFiles.push(path);
}
}
Expand Down Expand Up @@ -275,7 +278,7 @@

// deprecated
loadTemplateFile: function(paths, params) {
return filesLoader(paths, params);
return filesLoader({files: paths}, params);
},

load: function(module, params) {
Expand Down Expand Up @@ -401,7 +404,9 @@
});
if (diff.length !== 0) {
$log.warn('Module "', moduleName, '" attempted to redefine configuration for dependency. "', requireEntry.name, '"\n Additional Files Loaded:', diff);
promisesList.push(filesLoader(diff, params).then(function () {
var c = angular.copy(requireEntry);
c.files = diff;
promisesList.push(filesLoader(c, params).then(function () {
return loadDependencies(requireEntry);
}));
}
Expand All @@ -427,7 +432,7 @@
// Check if the dependency has any files that need to be loaded. If there are, push a new promise to the promise list.
if(requireEntry.hasOwnProperty('files') && requireEntry.files.length !== 0) {
if(requireEntry.files) {
promisesList.push(filesLoader(requireEntry.files, params).then(function() {
promisesList.push(filesLoader(requireEntry, params).then(function() {
return loadDependencies(requireEntry)
}));
}
Expand All @@ -438,14 +443,14 @@
return $q.all(promisesList);
}

filesLoader(config.files, params).then(function success() {
filesLoader(config, params).then(function success() {
if(moduleName === null) {
deferred.resolve(module);
} else {
moduleCache.push(moduleName);
loadDependencies(moduleName).then(function success() {
try {
register(providers, moduleCache);
register(providers, moduleCache, params);
} catch(e) {
$log.error(e.message);
deferred.reject(e);
Expand All @@ -471,24 +476,24 @@

this.config = function(config) {
if(angular.isDefined(config.jsLoader) || angular.isDefined(config.asyncLoader)) {
jsLoader = config.jsLoader || config.asyncLoader;
if(!angular.isFunction(jsLoader)) {
throw('The js loader needs to be a function');
}
jsLoader = config.jsLoader || config.asyncLoader;
}

if(angular.isDefined(config.cssLoader)) {
cssLoader = config.cssLoader;
if(!angular.isFunction(cssLoader)) {
throw('The css loader needs to be a function');
}
cssLoader = config.cssLoader;
}

if(angular.isDefined(config.templatesLoader)) {
templatesLoader = config.templatesLoader;
if(!angular.isFunction(templatesLoader)) {
throw('The template loader needs to be a function');
}
templatesLoader = config.templatesLoader;
}

// for bootstrap apps, we need to define the main module name
Expand Down Expand Up @@ -631,7 +636,7 @@
}
}

function invokeQueue(providers, queue) {
function invokeQueue(providers, queue, moduleName, reconfig) {
if(!queue) {
return;
}
Expand All @@ -645,7 +650,11 @@
} else {
throw new Error('unsupported provider ' + args[0]);
}
if(registerInvokeList(args[2][0])) {
var invoked = regConfigs.indexOf(moduleName);
if(registerInvokeList(args[2][0]) && (args[1] !== 'invoke' || (args[1] === 'invoke' && (!invoked || reconfig)))) {
if(!invoked) {
regConfigs.push(moduleName);
}
provider[args[1]].apply(provider, args[2]);
}
}
Expand All @@ -658,7 +667,7 @@
* @param registerModules
* @returns {*}
*/
function register(providers, registerModules) {
function register(providers, registerModules, params) {
if(registerModules) {
var k, moduleName, moduleFn, runBlocks = [];
for(k = registerModules.length - 1; k >= 0; k--) {
Expand All @@ -672,11 +681,11 @@
moduleFn = angular.module(moduleName);
if(regModules.indexOf(moduleName) === -1) { // new module
regModules.push(moduleName);
register(providers, moduleFn.requires);
register(providers, moduleFn.requires, params);
runBlocks = runBlocks.concat(moduleFn._runBlocks);
}
invokeQueue(providers, moduleFn._invokeQueue);
invokeQueue(providers, moduleFn._configBlocks);
invokeQueue(providers, moduleFn._invokeQueue, moduleName, params.reconfig);
invokeQueue(providers, moduleFn._configBlocks, moduleName, params.reconfig); // angular 1.3+
broadcast('ocLazyLoad.moduleLoaded', moduleName);
registerModules.pop();
}
Expand Down
4 changes: 2 additions & 2 deletions dist/ocLazyLoad.min.js

Large diffs are not rendered by default.

45 changes: 27 additions & 18 deletions examples/example1/js/ocLazyLoad.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* ocLazyLoad - Load modules on demand (lazy load) with angularJS
* @version v0.3.1
* @version v0.3.2
* @link https://github.com/ocombe/ocLazyLoad
* @license MIT
* @author Olivier Combe <olivier.combe@gmail.com>
Expand All @@ -9,6 +9,7 @@
'use strict';
var regModules = ['ng'],
regInvokes = [],
regConfigs = [],
ocLazyLoad = angular.module('oc.lazyLoad', ['ng']),
broadcast = angular.noop;

Expand Down Expand Up @@ -196,19 +197,21 @@
templatesLoader.ocLazyLoadLoader = true;
}

var filesLoader = function(paths, params) {
var filesLoader = function(config, params) {
var cssFiles = [],
templatesFiles = [],
jsFiles = [],
promises = [];

angular.forEach(paths, function(path) {
angular.extend(params || {}, config);

angular.forEach(params.files, function(path) {
if(angular.isUndefined(filesCache.get(path)) || params.cache === false) {
if(/\.css[^\.]*$/.test(path) && cssFiles.indexOf(path) === -1) {
cssFiles.push(path);
} else if(/\.(htm|html)[^\.]*$/.test(path) && templatesFiles.indexOf(path) === -1) {
templatesFiles.push(path);
} else if (/\.(js)[^\.]*$/.test(path) && jsFiles.indexOf(path) === -1) {
} else if (jsFiles.indexOf(path) === -1) {
jsFiles.push(path);
}
}
Expand Down Expand Up @@ -275,7 +278,7 @@

// deprecated
loadTemplateFile: function(paths, params) {
return filesLoader(paths, params);
return filesLoader({files: paths}, params);
},

load: function(module, params) {
Expand Down Expand Up @@ -401,7 +404,9 @@
});
if (diff.length !== 0) {
$log.warn('Module "', moduleName, '" attempted to redefine configuration for dependency. "', requireEntry.name, '"\n Additional Files Loaded:', diff);
promisesList.push(filesLoader(diff, params).then(function () {
var c = angular.copy(requireEntry);
c.files = diff;
promisesList.push(filesLoader(c, params).then(function () {
return loadDependencies(requireEntry);
}));
}
Expand All @@ -427,7 +432,7 @@
// Check if the dependency has any files that need to be loaded. If there are, push a new promise to the promise list.
if(requireEntry.hasOwnProperty('files') && requireEntry.files.length !== 0) {
if(requireEntry.files) {
promisesList.push(filesLoader(requireEntry.files, params).then(function() {
promisesList.push(filesLoader(requireEntry, params).then(function() {
return loadDependencies(requireEntry)
}));
}
Expand All @@ -438,14 +443,14 @@
return $q.all(promisesList);
}

filesLoader(config.files, params).then(function success() {
filesLoader(config, params).then(function success() {
if(moduleName === null) {
deferred.resolve(module);
} else {
moduleCache.push(moduleName);
loadDependencies(moduleName).then(function success() {
try {
register(providers, moduleCache);
register(providers, moduleCache, params);
} catch(e) {
$log.error(e.message);
deferred.reject(e);
Expand All @@ -471,24 +476,24 @@

this.config = function(config) {
if(angular.isDefined(config.jsLoader) || angular.isDefined(config.asyncLoader)) {
jsLoader = config.jsLoader || config.asyncLoader;
if(!angular.isFunction(jsLoader)) {
throw('The js loader needs to be a function');
}
jsLoader = config.jsLoader || config.asyncLoader;
}

if(angular.isDefined(config.cssLoader)) {
cssLoader = config.cssLoader;
if(!angular.isFunction(cssLoader)) {
throw('The css loader needs to be a function');
}
cssLoader = config.cssLoader;
}

if(angular.isDefined(config.templatesLoader)) {
templatesLoader = config.templatesLoader;
if(!angular.isFunction(templatesLoader)) {
throw('The template loader needs to be a function');
}
templatesLoader = config.templatesLoader;
}

// for bootstrap apps, we need to define the main module name
Expand Down Expand Up @@ -631,7 +636,7 @@
}
}

function invokeQueue(providers, queue) {
function invokeQueue(providers, queue, moduleName, reconfig) {
if(!queue) {
return;
}
Expand All @@ -645,7 +650,11 @@
} else {
throw new Error('unsupported provider ' + args[0]);
}
if(registerInvokeList(args[2][0])) {
var invoked = regConfigs.indexOf(moduleName);
if(registerInvokeList(args[2][0]) && (args[1] !== 'invoke' || (args[1] === 'invoke' && (!invoked || reconfig)))) {
if(!invoked) {
regConfigs.push(moduleName);
}
provider[args[1]].apply(provider, args[2]);
}
}
Expand All @@ -658,7 +667,7 @@
* @param registerModules
* @returns {*}
*/
function register(providers, registerModules) {
function register(providers, registerModules, params) {
if(registerModules) {
var k, moduleName, moduleFn, runBlocks = [];
for(k = registerModules.length - 1; k >= 0; k--) {
Expand All @@ -672,11 +681,11 @@
moduleFn = angular.module(moduleName);
if(regModules.indexOf(moduleName) === -1) { // new module
regModules.push(moduleName);
register(providers, moduleFn.requires);
register(providers, moduleFn.requires, params);
runBlocks = runBlocks.concat(moduleFn._runBlocks);
}
invokeQueue(providers, moduleFn._invokeQueue);
invokeQueue(providers, moduleFn._configBlocks);
invokeQueue(providers, moduleFn._invokeQueue, moduleName, params.reconfig);
invokeQueue(providers, moduleFn._configBlocks, moduleName, params.reconfig); // angular 1.3+
broadcast('ocLazyLoad.moduleLoaded', moduleName);
registerModules.pop();
}
Expand Down
Loading

0 comments on commit 3dab3fe

Please sign in to comment.