Skip to content

Commit

Permalink
Merge pull request #797 from podgorskiy/master
Browse files Browse the repository at this point in the history
Fixed components order.
  • Loading branch information
Golmote committed Oct 7, 2015
2 parents a6c0d02 + 06d3548 commit 7a6aed8
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion download.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,48 @@ function delayedGenerateCode(){
timerId = setTimeout(generateCode, 500);
}

function getSortedComponentsByRequirements(components){
var sorted = [];
for (var component in components) {
sorted.push(component);
}
var i = 0;
while (i < sorted.length) {
var id = sorted[i];
var indexOfRequirement = i;
var notNow = false;
for (var requirement in components[id].require) {
indexOfRequirement = sorted.indexOf(components[id].require[requirement]);
if (indexOfRequirement > i) {
notNow = true;
break;
}
}
if (notNow) {
tmp = sorted[i];
sorted[i] = sorted[indexOfRequirement];
sorted[indexOfRequirement] = tmp;
}
else {
i++;
}
}
return sorted;
}

function generateCode(){
var promises = [];
var redownload = {};

for (var category in components) {
var all = components[category];

for (var id in all) {
// In case if one component requires other, required component should go first.
var sorted = getSortedComponentsByRequirements(all);

for (var i = 0; i < sorted.length; i++) {
var id = sorted[i];

if(id === 'meta') {
continue;
}
Expand Down

0 comments on commit 7a6aed8

Please sign in to comment.