mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
@@ -8,7 +8,10 @@ import Header from "discourse/components/topic-list/header";
|
|||||||
import Item from "discourse/components/topic-list/item";
|
import Item from "discourse/components/topic-list/item";
|
||||||
import concatClass from "discourse/helpers/concat-class";
|
import concatClass from "discourse/helpers/concat-class";
|
||||||
import DAG from "discourse/lib/dag";
|
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 { i18n } from "discourse-i18n";
|
||||||
import HeaderActivityCell from "./header/activity-cell";
|
import HeaderActivityCell from "./header/activity-cell";
|
||||||
import HeaderBulkSelectCell from "./header/bulk-select-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",
|
"topic-list-columns",
|
||||||
defaultColumns,
|
defaultColumns,
|
||||||
context
|
context
|
||||||
|
@@ -345,11 +345,6 @@ export function applyValueTransformer(
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const value = valueCallback({ value: newValue, context });
|
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) {
|
if (!mutable) {
|
||||||
newValue = value;
|
newValue = value;
|
||||||
|
@@ -547,26 +547,6 @@ module("Unit | Utility | transformers", function (hooks) {
|
|||||||
applyMutableValueTransformer("test-mutable-transformer", value);
|
applyMutableValueTransformer("test-mutable-transformer", value);
|
||||||
assert.true(mutated, "the value is mutated");
|
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) {
|
module("pluginApi.addBehaviorTransformerName", function (innerHooks) {
|
||||||
|
Reference in New Issue
Block a user