Skip to content

Commit cf16be9

Browse files
committed
Merge pull request #775 from hannu/fix-module-issue
Fix issue when lazy loaded element overwrote last module with the same name
2 parents a19bdef + 5276c90 commit cf16be9

File tree

6 files changed

+55
-8
lines changed

6 files changed

+55
-8
lines changed

lib/app/js/app.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ angular.module('sgApp', [
9292

9393
function loadModule($ocLazyLoad) {
9494
if (window.filesConfig && window.filesConfig.length) {
95-
var fileNames = [];
96-
angular.forEach(window.filesConfig, function(file) {
97-
fileNames.push(file.name);
95+
var moduleNames = [];
96+
angular.forEach(window.filesConfig, function(lazyLoadmodule) {
97+
moduleNames.push(lazyLoadmodule.name);
9898
});
99-
return $ocLazyLoad.load(fileNames);
99+
return $ocLazyLoad.load(moduleNames);
100100
}
101101
}
102102

lib/app/sass/styleguide-app.scss

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1251,7 +1251,7 @@ Styleguide 4.4
12511251
//
12521252
// sg-angular-directive:
12531253
// name: sgAppTest
1254-
// template: demo/testDirective.html
1254+
// file: demo/testDirectiveInit.js
12551255
// file: demo/testDirective.js
12561256
//
12571257
// Styleguide 6.1
@@ -1262,11 +1262,23 @@ Styleguide 4.4
12621262
-webkit-user-select: none;
12631263
-ms-user-select: none;
12641264
padding: 0.2em;
1265-
border: 1px solid red;
1265+
border: 2px solid red;
12661266
display: initial;
12671267
cursor: pointer;
12681268
}
12691269

1270+
// Test directive2
1271+
//
1272+
// markup:
1273+
// <div sg-test-directive-two>If you see this something is wrong</div>
1274+
//
1275+
// sg-angular-directive:
1276+
// name: sgAppTest
1277+
// file: demo/testDirectiveInit.js
1278+
// file: demo/testDirectiveTwo.js
1279+
//
1280+
// Styleguide 6.2
1281+
12701282
// styleguide:ignore:start
12711283
@include styleguide_custom_styles;
12721284
// styleguide:ignore:end

lib/demo/testDirective.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// Test directive is used to demo lazy loading external directive in the test project
44

5-
angular.module('sgAppTest', [])
5+
angular.module('sgAppTest')
66
.controller('sgAppTest', function($scope) {
77
$scope.clickCount = 0;
88
$scope.incrementClicks = function() {

lib/demo/testDirectiveInit.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
angular.module('sgAppTest', []);

lib/demo/testDirectiveTwo.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use strict';
2+
3+
angular.module('sgAppTest')
4+
.controller('sgAppTest', function($scope) {
5+
$scope.clickCount = 0;
6+
$scope.incrementClicks = function() {
7+
$scope.clickCount += 1;
8+
};
9+
})
10+
.directive('sgTestDirectiveTwo', function() {
11+
return {
12+
replace: true,
13+
restrict: 'A',
14+
templateUrl: 'demo/testDirective.html'
15+
};
16+
});

lib/styleguide.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,24 @@ function emitCompileSuccess() {
6767
}
6868
}
6969

70+
function groupModuleFiles(allModules) {
71+
// Group modules by module name
72+
var namedModules = _.groupBy(allModules, function(module) {
73+
return module.name;
74+
});
75+
76+
// Commbile files from every module that has the same name
77+
return _.map(namedModules, function(modules, moduleName) {
78+
var files = _.uniq(_.reduce(modules, function(files, singleModule) {
79+
return files.concat(singleModule.files);
80+
}, []));
81+
return {
82+
name: moduleName,
83+
files: files
84+
};
85+
});
86+
}
87+
7088
function generateSectionWrapperMarkup(json) {
7189
json.section = wrapperMarkup.generateSectionWrapperMarkup(json.sections);
7290
}
@@ -291,7 +309,7 @@ module.exports.generate = function(options) {
291309
styleguideConfig: JSON.stringify(copyUsedOptionsToInlineJsonConfig(opt, {}).config),
292310
appRoot: opt.appRoot,
293311
socketIo: opt.server,
294-
filesConfig: JSON.stringify(opt.filesConfig)
312+
filesConfig: JSON.stringify(groupModuleFiles(opt.filesConfig))
295313
}))
296314
.pipe(pushAllFiles())
297315
.on('finish', resolve);

0 commit comments

Comments
 (0)