mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 03:22:46 +08:00
DEV: Make attachWidgetAction
fail gracefully when widget is missing (#21750)
This brings the behaviour in line with our other widget-related APIs like `decorateWidget` and `reopenWidget`. This commit also adds a theme/plugin prefix to the console messages.
This commit is contained in:
parent
036e27e69a
commit
d52198356c
|
@ -573,7 +573,17 @@ class PluginApi {
|
|||
attachWidgetAction(widget, actionName, fn) {
|
||||
const widgetClass =
|
||||
queryRegistry(widget) ||
|
||||
this.container.factoryFor(`widget:${widget}`).class;
|
||||
this.container.factoryFor(`widget:${widget}`)?.class;
|
||||
|
||||
if (!widgetClass) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(
|
||||
consolePrefix(),
|
||||
`attachWidgetAction: Could not find widget ${widget} in registry`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
widgetClass.prototype[actionName] = fn;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import { deepMerge } from "discourse-common/lib/object";
|
|||
import { get } from "@ember/object";
|
||||
import { h } from "virtual-dom";
|
||||
import { isProduction } from "discourse-common/config/environment";
|
||||
import { consolePrefix } from "discourse/lib/source-identifier";
|
||||
|
||||
const _registry = {};
|
||||
|
||||
|
@ -106,7 +107,10 @@ export function reopenWidget(name, opts) {
|
|||
let existing = _registry[name];
|
||||
if (!existing) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(`Could not find widget ${name} in registry`);
|
||||
console.error(
|
||||
consolePrefix(),
|
||||
`reopenWidget: Could not find widget ${name} in registry`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user