mirror of
https://github.com/discourse/discourse.git
synced 2025-06-02 16:29:32 +08:00
DEV: Make it possible to deprecate plugin outlet properties
This commit is contained in:
@ -21,7 +21,8 @@ var define, requirejs;
|
|||||||
getProperties: Ember.getProperties,
|
getProperties: Ember.getProperties,
|
||||||
set: Ember.set,
|
set: Ember.set,
|
||||||
setProperties: Ember.setProperties,
|
setProperties: Ember.setProperties,
|
||||||
computed: Ember.computed
|
computed: Ember.computed,
|
||||||
|
defineProperty: Ember.defineProperty
|
||||||
},
|
},
|
||||||
"@ember/object/computed": {
|
"@ember/object/computed": {
|
||||||
alias: Ember.computed.alias,
|
alias: Ember.computed.alias,
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
import Component from "@ember/component";
|
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({
|
export default Component.extend({
|
||||||
init() {
|
init() {
|
||||||
@ -9,10 +11,30 @@ export default Component.extend({
|
|||||||
this.set("layoutName", connector.templateName);
|
this.set("layoutName", connector.templateName);
|
||||||
|
|
||||||
const args = this.args || {};
|
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");
|
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);
|
this.set("actions", connectorClass.actions);
|
||||||
},
|
},
|
||||||
@ -24,12 +46,6 @@ export default Component.extend({
|
|||||||
connectorClass.teardownComponent.call(this, this);
|
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) {
|
send(name, ...args) {
|
||||||
const connectorClass = this.get("connector.connectorClass");
|
const connectorClass = this.get("connector.connectorClass");
|
||||||
const action = connectorClass.actions[name];
|
const action = connectorClass.actions[name];
|
||||||
|
@ -30,7 +30,7 @@ import Component from "@ember/component";
|
|||||||
The list of disabled plugins is returned via the `Site` singleton.
|
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({
|
export default Component.extend({
|
||||||
tagName: "span",
|
tagName: "span",
|
||||||
@ -46,7 +46,7 @@ export default Component.extend({
|
|||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
const name = this.name;
|
const name = this.name;
|
||||||
if (name) {
|
if (name) {
|
||||||
const args = this.args;
|
const args = buildArgsWithDeprecations(this.args || {}, this.deprecatedArgs || {});
|
||||||
this.set("connectors", renderedConnectorsFor(name, args, this));
|
this.set("connectors", renderedConnectorsFor(name, args, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import Site from "discourse/models/site";
|
import Site from "discourse/models/site";
|
||||||
|
import deprecated from "discourse-common/lib/deprecated";
|
||||||
|
|
||||||
let _connectorCache;
|
let _connectorCache;
|
||||||
let _rawConnectorCache;
|
let _rawConnectorCache;
|
||||||
@ -109,3 +110,23 @@ export function rawConnectorsFor(outletName) {
|
|||||||
}
|
}
|
||||||
return _rawConnectorCache[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;
|
||||||
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
{{#each connectors as |c|}}
|
{{#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}}
|
{{/each}}
|
||||||
|
Reference in New Issue
Block a user