feature: getRoute inherit extensions

This commit is contained in:
Jean-Baptiste Pasquier 2021-05-20 16:54:00 +02:00
parent 8f5aed11e0
commit 03f67009ab
1 changed files with 10 additions and 5 deletions

View File

@ -1,12 +1,17 @@
window.hubl.getRoute = (type, returnFirst = false) => {
let availables = window.hubl.components.filter(c => c.type == type || c.uniq == type);
if (availables.length > 1) {
if (returnFirst) {
let availables = components.filter(c=>c.type==type||c.uniq==type);
availables.map(c => {
if(c.extensions) {
c.extensions.forEach(e => availables.push(e.type));
}
});
if(availables.length > 1) {
if(returnFirst) {
return availables[0].route;
} else {
console.error(`Too much components availables for route ${type}`);
return availables[availables.length-1].route;
}
} else if (availables.length < 1) {
} else if(availables.length < 1) {
console.error(`No component found for route ${type}`);
} else {
return availables[0].route;