Skip to content

Commit df001d7

Browse files
committed
fix: dangling cleanup
1 parent 6d5c82b commit df001d7

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/tracker/view.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ export class CreatureView extends ItemView {
9595
statblockEl = this.contentEl.createDiv("creature-statblock-container");
9696
private currentCreatureId: string | null = null;
9797
private currentCreatureName: string | null = null;
98+
private bestiaryUnload: (() => void) | null = null;
9899
constructor(leaf: WorkspaceLeaf, public plugin: InitiativeTracker) {
99100
super(leaf);
100101
this.load();
@@ -133,6 +134,10 @@ export class CreatureView extends ItemView {
133134
});
134135
}
135136
onunload(): void {
137+
if (this.bestiaryUnload) {
138+
this.bestiaryUnload();
139+
this.bestiaryUnload = null;
140+
}
136141
this.app.workspace.trigger("initiative-tracker:stop-viewing");
137142
}
138143
getState(): Record<string, unknown> {
@@ -200,9 +205,15 @@ export class CreatureView extends ItemView {
200205
this.plugin.canUseStatBlocks &&
201206
!window["FantasyStatblocks"].isResolved()
202207
) {
208+
this.statblockEl.empty();
209+
this.statblockEl.createEl("em", {
210+
text: "Loading bestiary\u2026"
211+
});
203212
const unload = window["FantasyStatblocks"].onResolved(() => {
213+
this.bestiaryUnload = null;
204214
void tryRestore().finally(unload);
205215
});
216+
this.bestiaryUnload = unload;
206217
} else {
207218
await tryRestore();
208219
}

0 commit comments

Comments
 (0)