From 48c908c04d5de9f65b1c550ea93b112ddb937b2c Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Tue, 8 Oct 2024 02:51:08 +0900 Subject: [PATCH] DEV: Fix `ember/no-arrow-function-computed-properties` lint (#29110) --- .../app/components/plugin-connector.js | 50 ++++++++++--------- .../discourse/app/lib/plugin-connectors.js | 34 +++++++------ 2 files changed, 46 insertions(+), 38 deletions(-) diff --git a/app/assets/javascripts/discourse/app/components/plugin-connector.js b/app/assets/javascripts/discourse/app/components/plugin-connector.js index a871a0e8d0a..94d46fc25d5 100644 --- a/app/assets/javascripts/discourse/app/components/plugin-connector.js +++ b/app/assets/javascripts/discourse/app/components/plugin-connector.js @@ -22,16 +22,18 @@ export default class PluginConnector extends Component { init() { super.init(...arguments); - const args = this.args || {}; - Object.keys(args).forEach((key) => { - defineProperty( - this, - key, - computed("args", () => (this.args || {})[key]) - ); - }); + if (this.args) { + Object.keys(this.args).forEach((key) => { + defineProperty( + this, + key, + computed("args", function () { + return this.args[key]; + }) + ); + }); + } - const deprecatedArgs = this.deprecatedArgs || {}; const connectorInfo = { outletName: this.connector?.outletName, connectorName: this.connector?.connectorName, @@ -40,18 +42,20 @@ export default class PluginConnector extends Component { layoutName: this.layoutName, }; - Object.keys(deprecatedArgs).forEach((key) => { - defineProperty( - this, - key, - computed("deprecatedArgs", () => { - return deprecatedArgumentValue(deprecatedArgs[key], { - ...connectorInfo, - argumentName: key, - }); - }) - ); - }); + if (this.deprecatedArgs) { + Object.keys(this.deprecatedArgs).forEach((key) => { + defineProperty( + this, + key, + computed("deprecatedArgs", function () { + return deprecatedArgumentValue(this.deprecatedArgs[key], { + ...connectorInfo, + argumentName: key, + }); + }) + ); + }); + } const connectorClass = this.connector.connectorClass; this.set("actions", connectorClass?.actions); @@ -63,8 +67,8 @@ export default class PluginConnector extends Component { } const merged = buildArgsWithDeprecations( - args, - deprecatedArgs, + this.args, + this.deprecatedArgs, connectorInfo ); connectorClass?.setupComponent?.call(this, merged, this); diff --git a/app/assets/javascripts/discourse/app/lib/plugin-connectors.js b/app/assets/javascripts/discourse/app/lib/plugin-connectors.js index 11b4065945c..8e33c5c1cdf 100644 --- a/app/assets/javascripts/discourse/app/lib/plugin-connectors.js +++ b/app/assets/javascripts/discourse/app/lib/plugin-connectors.js @@ -241,22 +241,26 @@ export function rawConnectorsFor(outletName) { export function buildArgsWithDeprecations(args, deprecatedArgs, opts = {}) { const output = {}; - Object.keys(args).forEach((key) => { - Object.defineProperty(output, key, { value: args[key] }); - }); - - Object.keys(deprecatedArgs).forEach((argumentName) => { - Object.defineProperty(output, argumentName, { - get() { - const deprecatedArg = deprecatedArgs[argumentName]; - - return deprecatedArgumentValue(deprecatedArg, { - ...opts, - argumentName, - }); - }, + if (args) { + Object.keys(args).forEach((key) => { + Object.defineProperty(output, key, { value: args[key] }); }); - }); + } + + if (deprecatedArgs) { + Object.keys(deprecatedArgs).forEach((argumentName) => { + Object.defineProperty(output, argumentName, { + get() { + const deprecatedArg = deprecatedArgs[argumentName]; + + return deprecatedArgumentValue(deprecatedArg, { + ...opts, + argumentName, + }); + }, + }); + }); + } return output; }