feature: improve route for extensions

This commit is contained in:
Jean-Baptiste Pasquier 2021-05-20 16:59:49 +02:00
parent b7085a171e
commit e07cafb5c8
2 changed files with 24 additions and 16 deletions

View File

@ -1,17 +1,21 @@
window.hubl.getRoute = (type, returnFirst = false) => {
let availables = window.hubl.components.filter(c=>c.type==type||c.uniq==type);
availables.map(c => {
if(c.extensions) {
c.extensions.forEach(e => availables.push(e.type));
let availables = window.hubl.components.filter(c => c.type == type || c.uniq == type);
window.hubl.components.forEach(c => {
if (c.extensions) {
c.extensions.forEach(e => {
if (e.type == type || e.uniq == type) {
availables.push(e.type);
}
});
}
});
if(availables.length > 1) {
if(returnFirst) {
if (availables.length > 1) {
if (returnFirst) {
return availables[0].route;
} else {
return availables[availables.length-1].route;
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;

View File

@ -11,19 +11,23 @@
-
let routes = new Set();
const getRoute = (type, returnFirst = false) => {
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));
let availables = components.filter(c => c.type == type || c.uniq == type);
components.forEach(c => {
if (c.extensions) {
c.extensions.forEach(e => {
if (e.type == type || e.uniq == type) {
availables.push(e.type);
}
});
}
});
if(availables.length > 1) {
if(returnFirst) {
if (availables.length > 1) {
if (returnFirst) {
return availables[0].route;
} else {
return availables[availables.length-1].route;
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;