Skip to content

Commit d6df765

Browse files
salmanmkcdli7319
authored andcommitted
fix: store bound synccomplete handler so dispose() actually removes it
TextView.dispose() called removeEventListener with .bind(this), which creates a new function reference. The original listener was added with a different .bind(this) call, so removeEventListener silently failed and the listener was never removed. Store the bound function as a class property and use the same reference for both addEventListener and removeEventListener. Fixes #178 Signed-off-by: Salman Muin Kayser Chishti <13schishti@gmail.com>
1 parent a546487 commit d6df765

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/ui/components/TextView.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ export class TextView extends View<TextViewEventMap> {
146146
/** The total number of lines after text wrapping. */
147147
lineCount = 0;
148148

149+
private _onSyncCompleteBound = this.onSyncComplete.bind(this);
149150
private _initializeTextCalled = false;
150151
private _text = 'TextView';
151152
set text(text) {
@@ -372,7 +373,7 @@ export class TextView extends View<TextViewEventMap> {
372373
this.textObj.addEventListener(
373374
// @ts-expect-error Missing type in Troika
374375
'synccomplete',
375-
this.onSyncComplete.bind(this)
376+
this._onSyncCompleteBound
376377
);
377378

378379
if (this.imageOverlay) {
@@ -413,7 +414,7 @@ export class TextView extends View<TextViewEventMap> {
413414
this.textObj.removeEventListener(
414415
// @ts-expect-error Missing type in Troika
415416
'synccomplete',
416-
this.onSyncComplete.bind(this)
417+
this._onSyncCompleteBound
417418
);
418419
}
419420
super.dispose();

0 commit comments

Comments
 (0)