Commit 93d60201 authored by Jérome Perrin's avatar Jérome Perrin

monaco_editor: abort pending checkPythonSourceCode requests

In the previous approach, several "useless" request were still made
during edition.
parent d881b1e6
...@@ -107,6 +107,22 @@ $script.onload = function() { ...@@ -107,6 +107,22 @@ $script.onload = function() {
} }
var timeout = null; var timeout = null;
// minimal pollyfil for AbortController
if (self.AbortController === undefined) {
class AbortController {
constructor() {
this.signal = { aborted: false };
}
abort() {
this.signal.aborted = true;
}
}
console.log("AbortController not available");
self.AbortController = AbortController;
}
var controller = new AbortController();
function checkPythonSourceCode() { function checkPythonSourceCode() {
const data = new FormData(); const data = new FormData();
const checker_parameters = { const checker_parameters = {
...@@ -123,7 +139,8 @@ $script.onload = function() { ...@@ -123,7 +139,8 @@ $script.onload = function() {
data.append("data", JSON.stringify(checker_parameters)); data.append("data", JSON.stringify(checker_parameters));
fetch(portal_url + "/ERP5Site_checkPythonSourceCodeAsJSON", { fetch(portal_url + "/ERP5Site_checkPythonSourceCodeAsJSON", {
method: "POST", method: "POST",
body: data body: data,
signal: controller.signal
}) })
.then(response => response.json()) .then(response => response.json())
.then(data => { .then(data => {
...@@ -145,7 +162,12 @@ $script.onload = function() { ...@@ -145,7 +162,12 @@ $script.onload = function() {
}) })
); );
timeout = null; timeout = null;
}); }, e => {
if (!e instanceof DOMException /* AbortError */ ) {
throw e;
}
/* ignore aborted requests */
});
} }
editor.model.onDidChangeContent(event => { editor.model.onDidChangeContent(event => {
...@@ -153,6 +175,8 @@ $script.onload = function() { ...@@ -153,6 +175,8 @@ $script.onload = function() {
changed = true; /* global variable used in erp5.js for onbeforeunload event */ changed = true; /* global variable used in erp5.js for onbeforeunload event */
if (mode == "python") { if (mode == "python") {
// debounced `checkPythonSourceCode` // debounced `checkPythonSourceCode`
controller.abort();
controller = new AbortController();
if (timeout) { if (timeout) {
clearTimeout(timeout); clearTimeout(timeout);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment