mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 04:03:57 -06:00
FIX: prefers computed over discourseComputed (#16562)
We have currently unexpected behaviors when using @discourseComputed in a native class.
This commit is contained in:
parent
3e0cb8ea47
commit
c8757c9d1d
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user