Skip to content

Commit 943f215

Browse files
authored
Use named event handlers for cleanup (#5601)
1 parent 26be0e3 commit 943f215

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

js/activity.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7016,23 +7016,28 @@ class Activity {
70167016
// Throttle rendering when user is inactive and no music is playing
70177017
this._initIdleWatcher();
70187018

7019+
// Named event handlers for proper cleanup
70197020
let mouseEvents = 0;
7020-
document.addEventListener("mousemove", () => {
7021+
this.handleMouseMove = () => {
70217022
mouseEvents++;
70227023
if (mouseEvents % 4 === 0) {
70237024
that.__tick();
70247025
}
7025-
});
7026+
};
70267027

7027-
document.addEventListener("click", e => {
7028+
this.handleDocumentClick = e => {
70287029
if (!this.hasMouseMoved) {
70297030
if (this.selectionModeOn) {
70307031
this.deselectSelectedBlocks();
70317032
} else {
70327033
this._hideHelpfulSearchWidget(e);
70337034
}
70347035
}
7035-
});
7036+
};
7037+
7038+
// Use managed addEventListener for automatic cleanup
7039+
this.addEventListener(document, "mousemove", this.handleMouseMove);
7040+
this.addEventListener(document, "click", this.handleDocumentClick);
70367041

70377042
this._createMsgContainer(
70387043
"#ffffff",
@@ -7670,11 +7675,15 @@ class Activity {
76707675
document.addEventListener("DOMMouseScroll", scrollEvent, false);
76717676
*/
76727677

7678+
// Named event handler for proper cleanup
76737679
const activity = this;
7674-
document.onkeydown = () => {
7680+
this.handleKeyDown = event => {
76757681
activity.__keyPressed(event);
76767682
};
76777683

7684+
// Use managed addEventListener instead of onkeydown assignment
7685+
this.addEventListener(document, "keydown", this.handleKeyDown);
7686+
76787687
if (this.planet !== undefined) {
76797688
this.planet.planet.setAnalyzeProject(doAnalyzeProject);
76807689
}

0 commit comments

Comments
 (0)