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() {
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);

View File

@ -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;
}