mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 08:04:03 +08:00
Make attach
optionally take a list of widget names to try
This commit is contained in:
parent
41129f933d
commit
01a7fd4225
|
@ -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`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user