DEV: drops jquery usage in stacked chart (#14946)

This commit is contained in:
Joffrey JAFFEUX 2021-11-16 10:26:26 +01:00 committed by GitHub
parent 43659a6de2
commit c768c2ab3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 14 deletions

View File

@ -5,28 +5,21 @@ import loadScript from "discourse/lib/load-script";
import { makeArray } from "discourse-common/lib/helpers";
import { number } from "discourse/lib/formatter";
import { schedule } from "@ember/runloop";
import { bind } from "discourse-common/utils/decorators";
export default Component.extend({
classNames: ["admin-report-chart", "admin-report-stacked-chart"],
init() {
this._super(...arguments);
this.resizeHandler = () =>
discourseDebounce(this, this._scheduleChartRendering, 500);
},
didInsertElement() {
this._super(...arguments);
$(window).on("resize.chart", this.resizeHandler);
window.addEventListener("resize", this._resizeHandler);
},
willDestroyElement() {
this._super(...arguments);
$(window).off("resize.chart", this.resizeHandler);
window.removeEventListener("resize", this._resizeHandler);
this._resetChart();
},
@ -36,6 +29,11 @@ export default Component.extend({
discourseDebounce(this, this._scheduleChartRendering, 100);
},
@bind
_resizeHandler() {
discourseDebounce(this, this._scheduleChartRendering, 500);
},
_scheduleChartRendering() {
schedule("afterRender", () => {
if (!this.element) {
@ -149,9 +147,7 @@ export default Component.extend({
},
_resetChart() {
if (this._chart) {
this._chart.destroy();
this._chart = null;
}
this._chart?.destroy();
this._chart = null;
},
});