PR reviews

This commit is contained in:
Alan Guo Xiang Tan 2023-01-05 11:36:53 +08:00
parent f71e3c07dd
commit 1ee9356a54

View File

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