Merge pull request #164 from t47io/fix-bound-event-listener

Fix bound listener
This commit is contained in:
Prateeksha Singh 2018-04-24 00:52:35 +05:30 committed by GitHub
commit 08d0b93135
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 21 additions and 31 deletions

View File

@ -1312,8 +1312,6 @@ function prepareForExport(svg) {
return container.innerHTML;
}
let BOUND_DRAW_FN;
class BaseChart {
constructor(parent, options) {
@ -1394,18 +1392,15 @@ class BaseChart {
this.height = height - getExtraHeight(this.measures);
// Bind window events
BOUND_DRAW_FN = this.boundDrawFn.bind(this);
window.addEventListener('resize', BOUND_DRAW_FN);
window.addEventListener('orientationchange', this.boundDrawFn.bind(this));
this.boundDrawFn = () => this.draw(true);
window.addEventListener('resize', this.boundDrawFn);
window.addEventListener('orientationchange', this.boundDrawFn);
}
boundDrawFn() {
this.draw(true);
}
unbindWindowEvents() {
window.removeEventListener('resize', BOUND_DRAW_FN);
window.removeEventListener('orientationchange', this.boundDrawFn.bind(this));
destroy() {
// Unbind window events
window.removeEventListener('resize', this.boundDrawFn);
window.removeEventListener('orientationchange', this.boundDrawFn);
}
// Has to be called manually

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -301,7 +301,7 @@
chart.export();
// Unbind window-resize events
chart.unbindWindowEvents();
chart.destroy();
</code></pre>
</div>

View File

@ -7,8 +7,6 @@ import { getColor, isValidColor } from '../utils/colors';
import { runSMILAnimation } from '../utils/animation';
import { downloadFile, prepareForExport } from '../utils/export';
let BOUND_DRAW_FN;
export default class BaseChart {
constructor(parent, options) {
@ -89,18 +87,15 @@ export default class BaseChart {
this.height = height - getExtraHeight(this.measures);
// Bind window events
BOUND_DRAW_FN = this.boundDrawFn.bind(this);
window.addEventListener('resize', BOUND_DRAW_FN);
window.addEventListener('orientationchange', this.boundDrawFn.bind(this));
this.boundDrawFn = () => this.draw(true);
window.addEventListener('resize', this.boundDrawFn);
window.addEventListener('orientationchange', this.boundDrawFn);
}
boundDrawFn() {
this.draw(true);
}
unbindWindowEvents() {
window.removeEventListener('resize', BOUND_DRAW_FN);
window.removeEventListener('orientationchange', this.boundDrawFn.bind(this));
destroy() {
// Unbind window events
window.removeEventListener('resize', this.boundDrawFn);
window.removeEventListener('orientationchange', this.boundDrawFn);
}
// Has to be called manually