DEV: Ensure topic-tracking-state state change callbacks are cleaned up (#17069)
This commit is contained in:
parent
94c3bbc2d1
commit
95fa4c5d52
|
@ -4,6 +4,20 @@ import GlimmerComponent from "discourse/components/glimmer";
|
|||
import CategorySectionLink from "discourse/lib/sidebar/categories-section/category-section-link";
|
||||
|
||||
export default class SidebarCategoriesSection extends GlimmerComponent {
|
||||
constructor() {
|
||||
super(...arguments);
|
||||
|
||||
this.callbackId = this.topicTrackingState.onStateChange(() => {
|
||||
this.sectionLinks.forEach((sectionLink) => {
|
||||
sectionLink.refreshCounts();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
willDestroy() {
|
||||
this.topicTrackingState.offStateChange(this.callbackId);
|
||||
}
|
||||
|
||||
@cached
|
||||
get sectionLinks() {
|
||||
return this.site.trackedCategoriesList.map((trackedCategory) => {
|
||||
|
@ -13,8 +27,4 @@ export default class SidebarCategoriesSection extends GlimmerComponent {
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
willDestroy() {
|
||||
this.sectionLinks.forEach((sectionLink) => sectionLink.teardown());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,20 +14,11 @@ export default class CategorySectionLink {
|
|||
constructor({ category, topicTrackingState }) {
|
||||
this.category = category;
|
||||
this.topicTrackingState = topicTrackingState;
|
||||
|
||||
this.callbackId = this.topicTrackingState.onStateChange(
|
||||
this._refreshCounts
|
||||
);
|
||||
|
||||
this._refreshCounts();
|
||||
}
|
||||
|
||||
teardown() {
|
||||
this.topicTrackingState.offStateChange(this.callbackId);
|
||||
this.refreshCounts();
|
||||
}
|
||||
|
||||
@bind
|
||||
_refreshCounts() {
|
||||
refreshCounts() {
|
||||
this.totalUnread = this.topicTrackingState.countUnread({
|
||||
categoryId: this.category.id,
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue