PR reviews

This commit is contained in:
Alan Guo Xiang Tan 2023-01-05 11:36:53 +08:00
parent f71e3c07dd
commit 1ee9356a54
1 changed files with 11 additions and 16 deletions

View File

@ -2,9 +2,9 @@ import { inject as service } from "@ember/service";
import { action } from "@ember/object";
import { cached } from "@glimmer/tracking";
import { debounce } from "discourse-common/utils/decorators";
import Category from "discourse/models/category";
import SidebarCommonCategoriesSection from "discourse/components/sidebar/common/categories-section";
import discourseDebounce from "discourse-common/lib/debounce";
export const REFRESH_COUNTS_APP_EVENT_NAME =
"sidebar:refresh-categories-section-counts";
@ -18,10 +18,10 @@ export default class SidebarUserCategoriesSection extends SidebarCommonCategorie
super(...arguments);
this.callbackId = this.topicTrackingState.onStateChange(() => {
this.#refreshCounts();
this._refreshCounts();
});
this.appEvents.on(REFRESH_COUNTS_APP_EVENT_NAME, this, this.#refreshCounts);
this.appEvents.on(REFRESH_COUNTS_APP_EVENT_NAME, this, this._refreshCounts);
}
willDestroy() {
@ -32,22 +32,17 @@ export default class SidebarUserCategoriesSection extends SidebarCommonCategorie
this.appEvents.off(
REFRESH_COUNTS_APP_EVENT_NAME,
this,
this.#refreshCounts
this._refreshCounts
);
}
#refreshCounts() {
// TopicTrackingState changes or plugins can trigger this function so we debounce to ensure we're not refreshing
// unnecessarily.
discourseDebounce(
this,
() => {
this.sectionLinks.forEach((sectionLink) => {
sectionLink.refreshCounts();
});
},
300
);
// TopicTrackingState changes or plugins can trigger this function so we debounce to ensure we're not refreshing
// unnecessarily.
@debounce(300)
_refreshCounts() {
this.sectionLinks.forEach((sectionLink) => {
sectionLink.refreshCounts();
});
}
@cached