Prefer ?? and move disposable location

This commit is contained in:
Anthony Kim
2026-01-27 17:58:10 -08:00
parent 40342ecd1e
commit e2dabc77fd
3 changed files with 51 additions and 20 deletions
@@ -41,6 +41,23 @@ export class KittyImageRenderer implements IDisposable {
this._terminal = terminal;
}
public dispose(): void {
this._renderDisposable?.dispose();
this._resizeDisposable?.dispose();
// Close all bitmaps
for (const placement of this._placements.values()) {
placement.bitmap.close();
}
this._placements.clear();
if (this._canvas) {
this._canvas.remove();
this._canvas = undefined;
this._ctx = undefined;
}
}
/**
* Initialize the canvas layer. Called when first image is placed.
*/
@@ -217,21 +234,4 @@ export class KittyImageRenderer implements IDisposable {
this._draw();
}
}
public dispose(): void {
this._renderDisposable?.dispose();
this._resizeDisposable?.dispose();
// Close all bitmaps
for (const placement of this._placements.values()) {
placement.bitmap.close();
}
this._placements.clear();
if (this._canvas) {
this._canvas.remove();
this._canvas = undefined;
this._ctx = undefined;
}
}
}