DEV: Unsilence and resolve setting-on-hash deprecation (#20611)

Select-kit was mutating a passed-in options hash to apply its own deprecations. This commit updates it to apply deprecated changes to the downstream `this.selectKit.options` object instead.
This commit is contained in:
David Taylor 2023-03-09 13:44:31 +00:00 committed by GitHub
parent 3c4bfb6a9f
commit 059ac3d31a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 6 deletions

View File

@ -10,7 +10,6 @@ globalThis.deprecationWorkflow.config = {
{ handler: "silence", matchId: "route-render-template" },
{ handler: "silence", matchId: "routing.transition-methods" },
{ handler: "silence", matchId: "route-disconnect-outlet" },
{ handler: "silence", matchId: "setting-on-hash" },
{ handler: "silence", matchId: "this-property-fallback" },
{ handler: "silence", matchId: "ember.globals-resolver" },
{ handler: "silence", matchId: "globals-resolver" },

View File

@ -215,6 +215,7 @@ export default Component.extend(
didReceiveAttrs() {
this._super(...arguments);
const deprecatedOptions = this._resolveDeprecatedOptions();
const mergedOptions = Object.assign({}, ...this.selectKitOptions);
Object.keys(mergedOptions).forEach((key) => {
if (isPresent(this.options[key])) {
@ -222,6 +223,11 @@ export default Component.extend(
return;
}
if (isPresent(deprecatedOptions[`options.${key}`])) {
this.selectKit.options.set(key, deprecatedOptions[`options.${key}`]);
return;
}
const value = mergedOptions[key];
if (
@ -1055,7 +1061,7 @@ export default Component.extend(
handleDeprecations() {
this._deprecateValueAttribute();
this._deprecateMutations();
this._deprecateOptions();
this._handleDeprecatdArgs();
},
_computePlacementStrategy() {
@ -1116,11 +1122,8 @@ export default Component.extend(
}
},
_deprecateOptions() {
_resolveDeprecatedOptions() {
const migrations = {
headerIcon: "icon",
onExpand: "onOpen",
onCollapse: "onClose",
allowAny: "options.allowAny",
allowCreate: "options.allowAny",
filterable: "options.filterable",
@ -1141,6 +1144,29 @@ export default Component.extend(
castInteger: "options.castInteger",
};
const resolvedDeprecations = {};
Object.keys(migrations).forEach((from) => {
const to = migrations[from];
if (this.get(from) && !this.get(to)) {
this._deprecated(
`The \`${from}\` attribute is deprecated. Use \`${to}\` instead`
);
resolvedDeprecations[(to, this.get(from))];
}
});
return resolvedDeprecations;
},
_handleDeprecatdArgs() {
const migrations = {
headerIcon: "icon",
onExpand: "onOpen",
onCollapse: "onClose",
};
Object.keys(migrations).forEach((from) => {
const to = migrations[from];
if (this.get(from) && !this.get(to)) {