Merge pull request #238 from frappe/fix-event-listener
fix: destroying event listener on window
This commit is contained in:
commit
317136eec4
@ -261,7 +261,7 @@ redirect_to: "https://frappe.io/charts"
|
|||||||
chart.export();
|
chart.export();
|
||||||
|
|
||||||
// Unbind window-resize events
|
// Unbind window-resize events
|
||||||
chart.unbindWindowEvents();
|
chart.destroy();
|
||||||
|
|
||||||
</code></pre>
|
</code></pre>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@ -7,8 +7,6 @@ import { getColor, isValidColor } from '../utils/colors';
|
|||||||
import { runSMILAnimation } from '../utils/animation';
|
import { runSMILAnimation } from '../utils/animation';
|
||||||
import { downloadFile, prepareForExport } from '../utils/export';
|
import { downloadFile, prepareForExport } from '../utils/export';
|
||||||
|
|
||||||
let BOUND_DRAW_FN;
|
|
||||||
|
|
||||||
export default class BaseChart {
|
export default class BaseChart {
|
||||||
constructor(parent, options) {
|
constructor(parent, options) {
|
||||||
|
|
||||||
@ -90,18 +88,14 @@ export default class BaseChart {
|
|||||||
this.height = height - getExtraHeight(this.measures);
|
this.height = height - getExtraHeight(this.measures);
|
||||||
|
|
||||||
// Bind window events
|
// Bind window events
|
||||||
BOUND_DRAW_FN = this.boundDrawFn.bind(this);
|
this.boundDrawFn = () => this.draw(true);
|
||||||
window.addEventListener('resize', BOUND_DRAW_FN);
|
window.addEventListener('resize', this.boundDrawFn);
|
||||||
window.addEventListener('orientationchange', this.boundDrawFn.bind(this));
|
window.addEventListener('orientationchange', this.boundDrawFn);
|
||||||
}
|
}
|
||||||
|
|
||||||
boundDrawFn() {
|
destroy() {
|
||||||
this.draw(true);
|
window.removeEventListener('resize', this.boundDrawFn);
|
||||||
}
|
window.removeEventListener('orientationchange', this.boundDrawFn);
|
||||||
|
|
||||||
unbindWindowEvents() {
|
|
||||||
window.removeEventListener('resize', BOUND_DRAW_FN);
|
|
||||||
window.removeEventListener('orientationchange', this.boundDrawFn.bind(this));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has to be called manually
|
// Has to be called manually
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user