service2.js: Move abortController management upstream

Generally, any gramar checking will be cancellable and will need this.
This commit is contained in:
Simon Rozman 2024-05-13 13:21:30 +02:00
parent ff54607e7e
commit 5e339566f3

View File

@ -41,6 +41,7 @@ class BesService {
* Unregisters grammar checking service.
*/
unregister() {
if (this.abortController) this.abortController.abort()
besServices = besServices.filter(item => item !== this)
this.hostElement.removeEventListener('scroll', this.onScroll)
this.hostElement.spellcheck = this.originalSpellcheck
@ -55,6 +56,7 @@ class BesService {
this.proofingError = null // The first non-fatal error in grammar-checking run
this.proofingMatches = 0 // Number of grammar mistakes detected in entire grammar-checking run
this.updateStatusIcon('bes-status-loading', 'Besana preverja pravopis.')
this.abortController = new AbortController()
}
/**
@ -72,6 +74,7 @@ class BesService {
* @param {Response} response HTTP response
*/
onFailedProofing(response) {
delete this.abortController
this.updateStatusIcon(
'bes-status-error',
`Pri preverjanju pravopisa je prišlo do napake ${response.status} ${response.statusText}.`
@ -102,6 +105,7 @@ class BesService {
* Called when grammar-checking run is ended
*/
onEndProofing() {
delete this.abortController
if (this.proofingError) {
this.updateStatusIcon(
'bes-status-error',
@ -264,38 +268,9 @@ class BesDOMService extends BesService {
this.hostElement.removeEventListener('input', this.onInput)
this.hostElement.removeEventListener('beforeinput', this.onBeforeInput)
if (this.timer) clearTimeout(this.timer)
if (this.abortController) this.abortController.abort()
super.unregister()
}
/**
* Called initially when grammar-checking run is started
*/
onStartProofing() {
super.onStartProofing()
this.abortController = new AbortController()
}
/**
* Called when grammar-checking failed (as 500 Internal server error, timeout, etc.)
*
* This error is fatal and proofing will not continue.
*
* @param {Response} response HTTP response
*/
onFailedProofing(response) {
delete this.abortController
super.onFailedProofing(response)
}
/**
* Called when grammar-checking run is ended
*/
onEndProofing() {
delete this.abortController
super.onEndProofing()
}
/**
* Called to report scrolling
*/