Add PluginAPI for registering a connector class

This commit is contained in:
Robin Ward 2016-12-15 11:54:37 -05:00
parent 0348f23f6d
commit 250ca11416
1 changed files with 23 additions and 1 deletions

View File

@ -11,6 +11,7 @@ import { preventCloak } from 'discourse/widgets/post-stream';
import { h } from 'virtual-dom';
import { addFlagProperty } from 'discourse/components/site-header';
import { addPopupMenuOptionsCallback } from 'discourse/controllers/composer';
import { extraConnectorClass } from 'discourse/lib/plugin-connectors';
class PluginApi {
constructor(version, container) {
@ -330,12 +331,33 @@ class PluginApi {
addStorePluralization(thing, plural) {
this.container.lookup("store:main").addPluralization(thing, plural);
}
/**
* Register a Connector class for a particular outlet and connector.
*
* For example, if the outlet is `user-profile-primary` and your connector
* template is called `my-connector.hbs`:
*
* ```javascript
* api.registerConnectorClass('user-profile-primary', 'my-connector', {
* shouldRender(args, component) {
* return component.siteSettings.my_plugin_enabled;
* }
* });
* ```
*
* For more information on connector classes, see:
* https://meta.discourse.org/t/important-changes-to-plugin-outlets-for-ember-2-10/54136
**/
registerConnectorClass(outletName, connectorName, klass) {
extraConnectorClass(`${outletName}/${connectorName}`, klass);
}
}
let _pluginv01;
function getPluginApi(version) {
version = parseFloat(version);
if (version <= 0.5) {
if (version <= 0.6) {
if (!_pluginv01) {
_pluginv01 = new PluginApi(version, Discourse.__container__);
}