DEV: Mark topic-list-columns transformer as mutable (#31127)

`topic-list-columns` expects consumers to mutate the DAG, not return a
new one. This change means that themes/plugins do not need to remember
to `return columns` when using the transformer.

Also removes the exception when someone returns a value to a mutable
valueTransformer. This is essential for backward-compatibility.
This commit is contained in:
David Taylor 2025-02-03 17:57:58 +00:00 committed by GitHub
parent a8e10521c3
commit c731a918e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 5 additions and 27 deletions

View File

@ -8,7 +8,10 @@ import Header from "discourse/components/topic-list/header";
import Item from "discourse/components/topic-list/item";
import concatClass from "discourse/helpers/concat-class";
import DAG from "discourse/lib/dag";
import { applyValueTransformer } from "discourse/lib/transformer";
import {
applyMutableValueTransformer,
applyValueTransformer,
} from "discourse/lib/transformer";
import { i18n } from "discourse-i18n";
import HeaderActivityCell from "./header/activity-cell";
import HeaderBulkSelectCell from "./header/bulk-select-cell";
@ -98,7 +101,7 @@ export default class TopicList extends Component {
},
};
return applyValueTransformer(
return applyMutableValueTransformer(
"topic-list-columns",
defaultColumns,
context

View File

@ -345,11 +345,6 @@ export function applyValueTransformer(
try {
const value = valueCallback({ value: newValue, context });
if (mutable && typeof value !== "undefined") {
throw new Error(
`${prefix}: transformer "${transformerName}" expects the value to be mutated instead of returned. Remove the return value in your transformer.`
);
}
if (!mutable) {
newValue = value;

View File

@ -547,26 +547,6 @@ module("Unit | Utility | transformers", function (hooks) {
applyMutableValueTransformer("test-mutable-transformer", value);
assert.true(mutated, "the value is mutated");
});
test("raises an exception if the transformer returns a value different from undefined", function (assert) {
assert.throws(
() => {
withPluginApi("1.34.0", (api) => {
api.registerValueTransformer(
"test-mutable-transformer",
() => "unexpected value"
);
});
applyMutableValueTransformer(
"test-mutable-transformer",
"default value"
);
},
/expects the value to be mutated instead of returned. Remove the return value in your transformer./,
"logs warning to the console when the transformer returns a value different from undefined"
);
});
});
module("pluginApi.addBehaviorTransformerName", function (innerHooks) {