Commit 42c71bd5 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 afa7c234
......@@ -88,6 +88,8 @@ $script.onload = function() {
}
var timeout = null;
var controller = new AbortController();
function checkPythonSourceCode() {
const data = new FormData();
const checker_parameters = {
......@@ -104,7 +106,8 @@ $script.onload = function() {
data.append("data", JSON.stringify(checker_parameters));
fetch(portal_url + "/ERP5Site_checkPythonSourceCodeAsJSON", {
method: "POST",
body: data
body: data,
signal: controller.signal
})
.then(response => response.json())
.then(data => {
......@@ -126,7 +129,12 @@ $script.onload = function() {
})
);
timeout = null;
});
}, e => {
if (!e instanceof DOMException /* AbortError */ ) {
throw e;
}
/* ignore aborted requests */
});
}
editor.model.onDidChangeContent(event => {
......@@ -134,6 +142,8 @@ $script.onload = function() {
changed = true; /* global variable used in erp5.js for onbeforeunload event */
if (mode == "python") {
// debounced `checkPythonSourceCode`
controller.abort();
controller = new AbortController();
if (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