Skip to content

Commit c13c494

Browse files
authored
DEV: Replace api.modifyClass(model...) with api.addTrackedPostProperties (#190)
This commit replaces patching the model class with a call to the new API `addTrackedPostProperties` to add tracked properties to the model
1 parent b4cf3a0 commit c13c494

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

.discourse-compatibility

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
< 3.4.0.beta3-dev: b4cf3a065884816fa3f770248c2bf908ba65d8ac
12
< 3.4.0.beta1-dev: 5346b4bafba2c2fb817f030a473b7bbca97b909c
23
< 3.3.0.beta1-dev: 6750e10a6d9dfd3fc2c9a0cac5a83aca1a8ee401
34
3.1.999: 20aed65b909fb41e22181067dc990b52ab0b7a96

assets/javascripts/discourse/initializers/extend-for-translate-button.js

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { tracked } from "@glimmer/tracking";
21
import { ajax } from "discourse/lib/ajax";
32
import { popupAjaxError } from "discourse/lib/ajax-error";
43
import { withPluginApi } from "discourse/lib/plugin-api";
54
import { withSilencedDeprecations } from "discourse-common/lib/deprecated";
6-
import I18n from "I18n";
5+
import { i18n } from "discourse-i18n";
76
import ToggleTranslationButton from "../components/post-menu/toggle-translation-button";
87
import TranslatedPost from "../components/translated-post";
98

@@ -27,18 +26,14 @@ function customizePostMenu(api, container) {
2726
);
2827

2928
if (transformerRegistered) {
30-
// the plugin outlet is not updated when the post instance is modified unless we extend it to add the tracking to
31-
// the new properties
32-
api.modifyClass(
33-
"model:post",
34-
(Superclass) =>
35-
class extends Superclass {
36-
@tracked detectedLang;
37-
@tracked isTranslating;
38-
@tracked isTranslated;
39-
@tracked translatedText;
40-
@tracked translatedTitle;
41-
}
29+
// the plugin outlet is not updated when the post instance is modified unless we register the new properties as
30+
// tracked
31+
api.addTrackedPostProperties(
32+
"detectedLang",
33+
"isTranslating",
34+
"isTranslated",
35+
"translatedText",
36+
"translatedTitle"
4237
);
4338

4439
api.renderBeforeWrapperOutlet("post-menu", TranslatedPost);
@@ -86,7 +81,7 @@ function customizeWidgetPostMenu(api) {
8681
...titleElements,
8782
dec.h(
8883
"div.post-attribution",
89-
I18n.t("translator.translated_from", { language, translator })
84+
i18n("translator.translated_from", { language, translator })
9085
),
9186
dec.cooked(dec.attrs.translated_text),
9287
]);
@@ -151,6 +146,6 @@ function customizeWidgetPostMenu(api) {
151146
export default {
152147
name: "extend-for-translate-button",
153148
initialize() {
154-
withPluginApi("1.34.0", (api) => initializeTranslation(api));
149+
withPluginApi("1.39.2", (api) => initializeTranslation(api));
155150
},
156151
};

0 commit comments

Comments
 (0)