FIX: prefers computed over discourseComputed (#16562)

We have currently unexpected behaviors when using @discourseComputed in a native class.
This commit is contained in:
Joffrey JAFFEUX 2022-04-26 11:43:41 +02:00 committed by GitHub
parent 3e0cb8ea47
commit c8757c9d1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -1,13 +1,16 @@
import Component from "@ember/component";
import discourseComputed from "discourse-common/utils/decorators";
import { computed } from "@ember/object";
import domFromString from "discourse-common/lib/dom-from-string";
export default class BadgeButtonComponent extends Component {
tagName = "";
badge = null;
@discourseComputed("badge.description")
title(badgeDescription) {
return domFromString(`<div>${badgeDescription}</div>`)[0].innerText;
@computed("badge.description")
get title() {
if (this.badge?.description) {
return domFromString(`<div>${this.badge?.description}</div>`)[0]
.innerText;
}
}
}

View File

@ -56,6 +56,14 @@ discourseModule("Integration | Component | badge-button", function (hooks) {
async test(assert) {
assert.equal(query(".user-badge").title, "a good run", "it strips html");
this.set("badge", { description: "a bad run" });
assert.equal(
query(".user-badge").title,
"a bad run",
"it updates title when changing description"
);
},
});