refactor(js): send 'autosave:end' when there are no more pending promises
This commit is contained in:
parent
00d1552060
commit
f4f40ded6c
1 changed files with 8 additions and 1 deletions
|
@ -37,6 +37,7 @@ export class AutosaveController extends ApplicationController {
|
|||
#abortController?: AbortController;
|
||||
#latestPromise = Promise.resolve();
|
||||
#needsRetry = false;
|
||||
#pendingPromiseCount = 0;
|
||||
|
||||
connect() {
|
||||
this.#latestPromise = Promise.resolve();
|
||||
|
@ -119,11 +120,15 @@ export class AutosaveController extends ApplicationController {
|
|||
}
|
||||
|
||||
private didSucceed() {
|
||||
this.globalDispatch('autosave:end');
|
||||
this.#pendingPromiseCount -= 1;
|
||||
if (this.#pendingPromiseCount == 0) {
|
||||
this.globalDispatch('autosave:end');
|
||||
}
|
||||
}
|
||||
|
||||
private didFail(error: ResponseError) {
|
||||
this.#needsRetry = true;
|
||||
this.#pendingPromiseCount -= 1;
|
||||
this.globalDispatch('autosave:error', { error });
|
||||
}
|
||||
|
||||
|
@ -179,6 +184,8 @@ export class AutosaveController extends ApplicationController {
|
|||
}
|
||||
}
|
||||
|
||||
this.#pendingPromiseCount++;
|
||||
|
||||
return httpRequest(form.action, {
|
||||
method: 'patch',
|
||||
body: formData,
|
||||
|
|
Loading…
Reference in a new issue