DEV: Fix ember/no-arrow-function-computed-properties lint (#29110)

This commit is contained in:
Jarek Radosz 2024-10-08 02:51:08 +09:00 committed by GitHub
parent 1ba8b6b22a
commit 48c908c04d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 46 additions and 38 deletions

View File

@ -22,16 +22,18 @@ export default class PluginConnector extends Component {
init() { init() {
super.init(...arguments); super.init(...arguments);
const args = this.args || {}; if (this.args) {
Object.keys(args).forEach((key) => { Object.keys(this.args).forEach((key) => {
defineProperty( defineProperty(
this, this,
key, key,
computed("args", () => (this.args || {})[key]) computed("args", function () {
); return this.args[key];
}); })
);
});
}
const deprecatedArgs = this.deprecatedArgs || {};
const connectorInfo = { const connectorInfo = {
outletName: this.connector?.outletName, outletName: this.connector?.outletName,
connectorName: this.connector?.connectorName, connectorName: this.connector?.connectorName,
@ -40,18 +42,20 @@ export default class PluginConnector extends Component {
layoutName: this.layoutName, layoutName: this.layoutName,
}; };
Object.keys(deprecatedArgs).forEach((key) => { if (this.deprecatedArgs) {
defineProperty( Object.keys(this.deprecatedArgs).forEach((key) => {
this, defineProperty(
key, this,
computed("deprecatedArgs", () => { key,
return deprecatedArgumentValue(deprecatedArgs[key], { computed("deprecatedArgs", function () {
...connectorInfo, return deprecatedArgumentValue(this.deprecatedArgs[key], {
argumentName: key, ...connectorInfo,
}); argumentName: key,
}) });
); })
}); );
});
}
const connectorClass = this.connector.connectorClass; const connectorClass = this.connector.connectorClass;
this.set("actions", connectorClass?.actions); this.set("actions", connectorClass?.actions);
@ -63,8 +67,8 @@ export default class PluginConnector extends Component {
} }
const merged = buildArgsWithDeprecations( const merged = buildArgsWithDeprecations(
args, this.args,
deprecatedArgs, this.deprecatedArgs,
connectorInfo connectorInfo
); );
connectorClass?.setupComponent?.call(this, merged, this); connectorClass?.setupComponent?.call(this, merged, this);

View File

@ -241,22 +241,26 @@ export function rawConnectorsFor(outletName) {
export function buildArgsWithDeprecations(args, deprecatedArgs, opts = {}) { export function buildArgsWithDeprecations(args, deprecatedArgs, opts = {}) {
const output = {}; const output = {};
Object.keys(args).forEach((key) => { if (args) {
Object.defineProperty(output, key, { value: args[key] }); 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 (deprecatedArgs) {
Object.keys(deprecatedArgs).forEach((argumentName) => {
Object.defineProperty(output, argumentName, {
get() {
const deprecatedArg = deprecatedArgs[argumentName];
return deprecatedArgumentValue(deprecatedArg, {
...opts,
argumentName,
});
},
});
});
}
return output; return output;
} }