A platform for community discussion. Free, open, simple.
Make `attach` optionally take a list of widget names to try
Daniel Waterworth01a7fd422570
diff --git a/app/assets/javascripts/discourse/widgets/widget.js.es6 b/app/assets/javascripts/discourse/widgets/widget.js.es6index e1b10163898..57290d7b1ef 100644--- a/app/assets/javascripts/discourse/widgets/widget.js.es6+++ b/app/assets/javascripts/discourse/widgets/widget.js.es6@@ -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-consoleconsole.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`);}}