feature: improve route for extensions
This commit is contained in:
parent
b7085a171e
commit
e07cafb5c8
@ -1,17 +1,21 @@
|
|||||||
window.hubl.getRoute = (type, returnFirst = false) => {
|
window.hubl.getRoute = (type, returnFirst = false) => {
|
||||||
let availables = window.hubl.components.filter(c=>c.type==type||c.uniq==type);
|
let availables = window.hubl.components.filter(c => c.type == type || c.uniq == type);
|
||||||
availables.map(c => {
|
window.hubl.components.forEach(c => {
|
||||||
if(c.extensions) {
|
if (c.extensions) {
|
||||||
c.extensions.forEach(e => availables.push(e.type));
|
c.extensions.forEach(e => {
|
||||||
|
if (e.type == type || e.uniq == type) {
|
||||||
|
availables.push(e.type);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(availables.length > 1) {
|
if (availables.length > 1) {
|
||||||
if(returnFirst) {
|
if (returnFirst) {
|
||||||
return availables[0].route;
|
return availables[0].route;
|
||||||
} else {
|
} 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}`);
|
console.error(`No component found for route ${type}`);
|
||||||
} else {
|
} else {
|
||||||
return availables[0].route;
|
return availables[0].route;
|
||||||
|
@ -11,19 +11,23 @@
|
|||||||
-
|
-
|
||||||
let routes = new Set();
|
let routes = new Set();
|
||||||
const getRoute = (type, returnFirst = false) => {
|
const getRoute = (type, returnFirst = false) => {
|
||||||
let availables = components.filter(c=>c.type==type||c.uniq==type);
|
let availables = components.filter(c => c.type == type || c.uniq == type);
|
||||||
availables.map(c => {
|
components.forEach(c => {
|
||||||
if(c.extensions) {
|
if (c.extensions) {
|
||||||
c.extensions.forEach(e => availables.push(e.type));
|
c.extensions.forEach(e => {
|
||||||
|
if (e.type == type || e.uniq == type) {
|
||||||
|
availables.push(e.type);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if(availables.length > 1) {
|
if (availables.length > 1) {
|
||||||
if(returnFirst) {
|
if (returnFirst) {
|
||||||
return availables[0].route;
|
return availables[0].route;
|
||||||
} else {
|
} 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}`);
|
console.error(`No component found for route ${type}`);
|
||||||
} else {
|
} else {
|
||||||
return availables[0].route;
|
return availables[0].route;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user