mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
DEV: New Plugin API method for delegating an app event
This commit is contained in:
parent
2ec0a17bef
commit
844c05b70b
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user