Skip to content

Commit

Permalink
Fix leaking TimeGraphVerticalScrollbarHandle instances
Browse files Browse the repository at this point in the history
Add moveEnd handler method to document event listeners in the moveStart
method and remove the listener in the moveEnd method.

Fixes #191.

Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
  • Loading branch information
PatrickTasse committed Apr 12, 2022
1 parent 4020833 commit 188c4da
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions timeline-chart/src/layer/time-graph-vertical-scrollbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class TimeGraphVerticalScrollbarHandle extends TimeGraphComponent<null> {

protected height: number;
protected position: TimeGraphElementPosition;
private _moveEndHandler;

constructor(protected rowController: TimeGraphRowController, protected stateController: TimeGraphStateController, protected factor: number) {
super('vscroll_handle');
Expand All @@ -63,9 +64,11 @@ export class TimeGraphVerticalScrollbarHandle extends TimeGraphComponent<null> {
this.oldVerticalOffset = this.rowController.verticalOffset;
this.mouseIsDown = true;
this.stateController.snapped = false;
document.addEventListener('snap-y-end', this._moveEndHandler);
};
const moveEnd = () => {
this._moveEndHandler = () => {
this.mouseIsDown = false;
document.removeEventListener('snap-y-end', this._moveEndHandler);
}
this.addEvent('mouseover', (event) => {
if (this.stateController.snapped) {
Expand All @@ -80,9 +83,8 @@ export class TimeGraphVerticalScrollbarHandle extends TimeGraphComponent<null> {
this.rowController.verticalOffset = Math.max(0, Math.min(this.rowController.totalHeight - this.stateController.canvasDisplayHeight, verticalOffset));
}
}, this._displayObject);
this.addEvent('mouseup', moveEnd, this._displayObject);
this.addEvent('mouseupoutside', moveEnd, this._displayObject);
document.addEventListener('snap-y-end', moveEnd);
this.addEvent('mouseup', this._moveEndHandler, this._displayObject);
this.addEvent('mouseupoutside', this._moveEndHandler, this._displayObject);
}

updateFactor(factor: number) {
Expand Down

0 comments on commit 188c4da

Please sign in to comment.