ignore pending requests for async table filters if new input exists

closes #325
This commit is contained in:
Felix Hamann 2019-06-05 22:17:45 +02:00
parent a5dcdaae0b
commit 70b0e536cf

View File

@ -38,6 +38,7 @@ export class AsyncTable {
change: [], change: [],
select: [], select: [],
}; };
_ignoreRequest = false;
constructor(element, app) { constructor(element, app) {
if (!element) { if (!element) {
@ -174,6 +175,10 @@ export class AsyncTable {
} }
}, INPUT_DEBOUNCE); }, INPUT_DEBOUNCE);
input.addEventListener('input', debouncedInput); input.addEventListener('input', debouncedInput);
input.addEventListener('input', () => {
// set flag to ignore any currently pending requests (not debounced)
this._ignoreRequest = true;
});
}); });
this._tableFilterInputs.input.forEach((input) => { this._tableFilterInputs.input.forEach((input) => {
@ -183,6 +188,10 @@ export class AsyncTable {
} }
}, INPUT_DEBOUNCE); }, INPUT_DEBOUNCE);
input.addEventListener('input', debouncedInput); input.addEventListener('input', debouncedInput);
input.addEventListener('input', () => {
// set flag to ignore any currently pending requests (not debounced)
this._ignoreRequest = true;
});
}); });
this._tableFilterInputs.change.forEach((input) => { this._tableFilterInputs.change.forEach((input) => {
@ -224,6 +233,7 @@ export class AsyncTable {
} }
}; };
} }
this._ignoreRequest = false;
this._updateTableFrom(url, callback); this._updateTableFrom(url, callback);
} }
@ -340,8 +350,13 @@ export class AsyncTable {
url: url, url: url,
headers: headers, headers: headers,
}).then( }).then(
(response) => this._app.htmlHelpers.parseResponse(response) (response) => this._app.htmlHelpers.parseResponse(response),
).then((response) => { ).then((response) => {
// check if request should be ignored
if (this._ignoreRequest) {
return false;
}
setLocalStorageParameter('currentTableUrl', url.href); setLocalStorageParameter('currentTableUrl', url.href);
// reset table // reset table
this._removeListeners(); this._removeListeners();