Skip to content

A platform for community discussion. Free, open, simple.

DEV: Make it possible to deprecate plugin outlet properties

Daniel Waterworthd54118390641
diff --git a/app/assets/javascripts/discourse-loader.js b/app/assets/javascripts/discourse-loader.js
index 6b8f90de229..694977cf76f 100644
--- a/app/assets/javascripts/discourse-loader.js
+++ b/app/assets/javascripts/discourse-loader.js
@@ -21,7 +21,8 @@ var define, requirejs;
getProperties: Ember.getProperties,
set: Ember.set,
setProperties: Ember.setProperties,
- computed: Ember.computed
+ computed: Ember.computed,
+ defineProperty: Ember.defineProperty
},
"@ember/object/computed": {
alias: Ember.computed.alias,
diff --git a/app/assets/javascripts/discourse/components/plugin-connector.js.es6 b/app/assets/javascripts/discourse/components/plugin-connector.js.es6
index a844ebbf9d1..393704974b9 100644
--- a/app/assets/javascripts/discourse/components/plugin-connector.js.es6
+++ b/app/assets/javascripts/discourse/components/plugin-connector.js.es6
@@ -1,5 +1,7 @@
import Component from "@ember/component";
-import { observes } from "discourse-common/utils/decorators";
+import { defineProperty, computed } from "@ember/object";
+import deprecated from "discourse-common/lib/deprecated";
+import { buildArgsWithDeprecations } from "discourse/lib/plugin-connectors";
export default Component.extend({
init() {
@@ -9,10 +11,30 @@ export default Component.extend({
this.set("layoutName", connector.templateName);
const args = this.args || {};
- Object.keys(args).forEach(key => this.set(key, args[key]));
+ Object.keys(args).forEach(key => {
+ defineProperty(
+ this,
+ key,
+ computed("args", () => (this.args || {})[key])
+ );
+ });
+
+ const deprecatedArgs = this.deprecatedArgs || {};
+ Object.keys(deprecatedArgs).forEach(key => {
+ defineProperty(
+ this,
+ key,
+ computed("deprecatedArgs", () => {
+ deprecated(`The ${key} property is deprecated, but is being used in ${this.layoutName}`);
+
+ return (this.deprecatedArgs || {})[key];
+ })
+ );
+ });
const connectorClass = this.get("connector.connectorClass");
- connectorClass.setupComponent.call(this, args, this);
+ const merged = buildArgsWithDeprecations(args, deprecatedArgs);
+ connectorClass.setupComponent.call(this, merged, this);
this.set("actions", connectorClass.actions);
},
@@ -24,12 +46,6 @@ export default Component.extend({
connectorClass.teardownComponent.call(this, this);
},
- @observes("args")
- _argsChanged() {
- const args = this.args || {};
- Object.keys(args).forEach(key => this.set(key, args[key]));
- },
-
send(name, ...args) {
const connectorClass = this.get("connector.connectorClass");
const action = connectorClass.actions[name];
diff --git a/app/assets/javascripts/discourse/components/plugin-outlet.js.es6 b/app/assets/javascripts/discourse/components/plugin-outlet.js.es6
index 14e3805964d..6cda10ce7cc 100644
--- a/app/assets/javascripts/discourse/components/plugin-outlet.js.es6
+++ b/app/assets/javascripts/discourse/components/plugin-outlet.js.es6
@@ -30,7 +30,7 @@ import Component from "@ember/component";
The list of disabled plugins is returned via the `Site` singleton.
**/
-import { renderedConnectorsFor } from "discourse/lib/plugin-connectors";
+import { renderedConnectorsFor, buildArgsWithDeprecations } from "discourse/lib/plugin-connectors";
export default Component.extend({
tagName: "span",
@@ -46,7 +46,7 @@ export default Component.extend({
this._super(...arguments);
const name = this.name;
if (name) {
- const args = this.args;
+ const args = buildArgsWithDeprecations(this.args || {}, this.deprecatedArgs || {});
this.set("connectors", renderedConnectorsFor(name, args, this));
}
}
diff --git a/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6 b/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6
index 6dbc62f2d52..20c356e99d9 100644
--- a/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6
+++ b/app/assets/javascripts/discourse/lib/plugin-connectors.js.es6
@@ -1,4 +1,5 @@
import Site from "discourse/models/site";
+import deprecated from "discourse-common/lib/deprecated";
let _connectorCache;
let _rawConnectorCache;
@@ -109,3 +110,23 @@ export function rawConnectorsFor(outletName) {
}
return _rawConnectorCache[outletName] || [];
}
+
+export function buildArgsWithDeprecations(args, deprecatedArgs) {
+ const output = {};
+
+ Object.keys(args).forEach(key => {
+ Object.defineProperty(output, key, { value: args[key] });
+ });
+
+ Object.keys(deprecatedArgs).forEach(key => {
+ Object.defineProperty(output, key, {
+ get() {
+ deprecated(`${key} is deprecated`);
+
+ return deprecatedArgs[key];
+ }
+ });
+ });
+
+ return output;
+}
diff --git a/app/assets/javascripts/discourse/templates/components/plugin-outlet.hbs b/app/assets/javascripts/discourse/templates/components/plugin-outlet.hbs
index 73126a2572f..8dbfeec09d3 100644
--- a/app/assets/javascripts/discourse/templates/components/plugin-outlet.hbs
+++ b/app/assets/javascripts/discourse/templates/components/plugin-outlet.hbs
@@ -1,3 +1,3 @@
{{#each connectors as |c|}}
- {{plugin-connector connector=c args=args class=c.classNames tagName=connectorTagName}}
+ {{plugin-connector connector=c args=args deprecatedArgs=deprecatedArgs class=c.classNames tagName=connectorTagName}}
{{/each}}