mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -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 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";
|
import domFromString from "discourse-common/lib/dom-from-string";
|
||||||
|
|
||||||
export default class BadgeButtonComponent extends Component {
|
export default class BadgeButtonComponent extends Component {
|
||||||
tagName = "";
|
tagName = "";
|
||||||
badge = null;
|
badge = null;
|
||||||
|
|
||||||
@discourseComputed("badge.description")
|
@computed("badge.description")
|
||||||
title(badgeDescription) {
|
get title() {
|
||||||
return domFromString(`<div>${badgeDescription}</div>`)[0].innerText;
|
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) {
|
async test(assert) {
|
||||||
assert.equal(query(".user-badge").title, "a good run", "it strips html");
|
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