Make attach optionally take a list of widget names to try

This commit is contained in:
Daniel Waterworth 2019-06-06 17:00:14 +01:00 committed by Robin Ward
parent 41129f933d
commit 01a7fd4225

View File

@ -270,18 +270,26 @@ export default class Widget {
}
}
attach(widgetName, attrs, opts) {
let WidgetClass = _registry[widgetName];
attach(widgetNames, attrs, opts) {
widgetNames = [].concat(widgetNames);
let WidgetClass = null;
for (let widgetName of widgetNames) {
WidgetClass = _registry[widgetName];
if (WidgetClass) {
break;
}
if (!WidgetClass) {
if (!this.register) {
// eslint-disable-next-line no-console
console.error("couldn't find register");
return;
}
WidgetClass = this.register.lookupFactory(`widget:${widgetName}`);
if (WidgetClass && WidgetClass.class) {
WidgetClass = WidgetClass.class;
break;
}
}
@ -291,7 +299,7 @@ export default class Widget {
result.dirtyKeys = this.dirtyKeys;
return result;
} else {
throw new Error(`Couldn't find ${widgetName} factory`);
throw new Error(`Couldn't find ${widgetNames} factory`);
}
}