Skip to content

Commit

Permalink
fix: allow components with the same name from different types/modules
Browse files Browse the repository at this point in the history
You can have multiple directives with the same name, and you can have controllers with the same name as a directive.
We now distinguish components from different modules, and components from different types.

Fixes #67
  • Loading branch information
ocombe committed Nov 2, 2014
1 parent bcf5000 commit f981c33
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/ocLazyLoad.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function() {
'use strict';
var regModules = ['ng'],
regInvokes = [],
regInvokes = {},
regConfigs = [],
justLoaded = [],
ocLazyLoad = angular.module('oc.lazyLoad', ['ng']),
Expand Down Expand Up @@ -663,7 +663,7 @@
throw new Error('unsupported provider ' + args[0]);
}
}
var isNew = registerInvokeList(args[2][0]);
var isNew = registerInvokeList(args, moduleName);
if(args[1] !== 'invoke') {
if(isNew && angular.isDefined(provider)) {
provider[args[1]].apply(provider, args[2]);
Expand Down Expand Up @@ -733,23 +733,29 @@

/**
* Register an invoke
* @param invokeList
* @param args
* @returns {*}
*/
function registerInvokeList(invokeList) {
var newInvoke = false;
function registerInvokeList(args, moduleName) {
var invokeList = args[2][0],
type = args[1],
newInvoke = false;
if(angular.isUndefined(regInvokes[moduleName])) {
regInvokes[moduleName] = {};
}
if(angular.isUndefined(regInvokes[moduleName][type])) {
regInvokes[moduleName][type] = [];
}
var onInvoke = function(invokeName) {
newInvoke = true;
regInvokes.push(invokeName);
broadcast('ocLazyLoad.componentLoaded', invokeName);
regInvokes[moduleName][type].push(invokeName);
}
if(angular.isString(invokeList)) {
if(regInvokes.indexOf(invokeList) === -1) {
onInvoke(invokeList);
}
if(angular.isString(invokeList) && regInvokes[moduleName][type].indexOf(invokeList) === -1) {
onInvoke(invokeList);
} else if(angular.isObject(invokeList)) {
angular.forEach(invokeList, function(invoke) {
if(angular.isString(invoke) && regInvokes.indexOf(invoke) === -1) {
if(angular.isString(invoke) && regInvokes[moduleName][type].indexOf(invoke) === -1) {
onInvoke(invoke);
}
});
Expand Down

0 comments on commit f981c33

Please sign in to comment.