diff --git a/service2.js b/service2.js index a210059..ed33cb3 100644 --- a/service2.js +++ b/service2.js @@ -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 */