This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/components/plugin-connector.js.es6
Daniel Waterworth 3b5c214ac3 DEV: fix linting
2019-11-20 14:03:45 +00:00

57 lines
1.6 KiB
JavaScript

import Component from "@ember/component";
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() {
this._super(...arguments);
const connector = this.connector;
this.set("layoutName", connector.templateName);
const args = this.args || {};
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 merged = buildArgsWithDeprecations(args, deprecatedArgs);
connectorClass.setupComponent.call(this, merged, this);
this.set("actions", connectorClass.actions);
},
willDestroyElement() {
this._super(...arguments);
const connectorClass = this.get("connector.connectorClass");
connectorClass.teardownComponent.call(this, this);
},
send(name, ...args) {
const connectorClass = this.get("connector.connectorClass");
const action = connectorClass.actions[name];
return action ? action.call(this, ...args) : this._super(name, ...args);
}
});