DEV: New Plugin API method for delegating an app event

DEV: New Plugin API method for delegating an app event

diff --git a/app/assets/javascripts/discourse/app/lib/plugin-api.js b/app/assets/javascripts/discourse/app/lib/plugin-api.js
index 3e2bf32..fa3d98c 100644
--- a/app/assets/javascripts/discourse/app/lib/plugin-api.js
+++ b/app/assets/javascripts/discourse/app/lib/plugin-api.js
@@ -81,7 +81,7 @@ import { addSearchResultsCallback } from "discourse/lib/search";
 import { addSearchSuggestion } from "discourse/widgets/search-menu-results";
 
 // If you add any methods to the API ensure you bump up this number
-const PLUGIN_API_VERSION = "0.12.0";
+const PLUGIN_API_VERSION = "0.12.1";
 
 class PluginApi {
   constructor(version, container) {
@@ -1316,13 +1316,35 @@ class PluginApi {
    * Add a suggestion shortcut to search menu panel.
    *
    * `‍``
-   * addSearchSuggestion("in:assigned");
+   * api.addSearchSuggestion("in:assigned");
    * `‍``
    *
    */
   addSearchSuggestion(value) {
     addSearchSuggestion(value);
   }
+
+  /**
+   * Calls a method on a mounted widget whenever an app event happens.
+   *
+   * For example, if you have a widget with a `key` of `cool-widget` that lives inside the
+   * `site-header` component, and you wanted it to respond to `thing:happened`, you could do this:
+   *
+   * `‍``
+   * api.dispatchWidgetAppEvent('site-header', 'cool-widget', 'thing:happened');
+   * `‍``
+   *
+   * In this case, the `cool-widget` must have a method called `thingHappened`. The event name
+   * is converted to camelCase and used as the method name for you.
+   */
+  dispatchWidgetAppEvent(mountedComponent, widgetKey, appEvent) {
+    this.modifyClass(`component:${mountedComponent}`, {
+      didInsertElement() {
+        this._super();
+        this.dispatch(appEvent, widgetKey);
+      },
+    });
+  }
 }
 
 // from http://stackoverflow.com/questions/6832596/how-to-compare-software-version-number-using-js-only-number

GitHub sha: 844c05b70b5d835fa7992e452d60a18892f4fee6

This commit appears in #13963 which was approved by romanrizzi. It was merged by eviltrout.