Skip to content

Commit

Permalink
refactor: fix noteviewcontroller de-init
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara committed Mar 22, 2023
1 parent 151cfd2 commit 9adfb0a
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class NoteViewController implements ItemViewControllerInterface {
private saveTimeout?: ReturnType<typeof setTimeout>
private defaultTagUuid: UuidString | undefined
private defaultTag?: SNTag
private savingLocallyPromise = Deferred<void>()
private savingLocallyPromise: ReturnType<typeof Deferred<void>> | null = null

constructor(
private application: WebApplication,
Expand All @@ -59,6 +59,11 @@ export class NoteViewController implements ItemViewControllerInterface {
}

deinit(): void {
if (!this.savingLocallyPromise) {
this.performDeinitSafely()
return
}

void this.savingLocallyPromise.promise.then(() => {
this.performDeinitSafely()
})
Expand Down Expand Up @@ -212,7 +217,9 @@ export class NoteViewController implements ItemViewControllerInterface {
void this.undebouncedSave({
...params,
onLocalPropagationComplete: () => {
this.savingLocallyPromise.resolve()
if (this.savingLocallyPromise) {
this.savingLocallyPromise.resolve()
}
resolve()
},
})
Expand Down

0 comments on commit 9adfb0a

Please sign in to comment.