Make sure to not double-fetch on collection change

Fixes #532
This commit is contained in:
rijkvanzanten
2020-10-20 16:17:17 -04:00
parent 932cd4a93a
commit 3879ae6969

View File

@@ -100,12 +100,16 @@ export function useItems(collection: Ref<string>, query: Query) {
}
});
let loadingTimeout: number | null = null;
return { itemCount, totalCount, items, totalPages, loading, error, changeManualSort, getItems };
async function getItems() {
if (loadingTimeout) return;
error.value = null;
const loadingTimeout = setTimeout(() => {
loadingTimeout = setTimeout(() => {
loading.value = true;
}, 250);
@@ -182,6 +186,7 @@ export function useItems(collection: Ref<string>, query: Query) {
error.value = err;
} finally {
clearTimeout(loadingTimeout);
loadingTimeout = null;
loading.value = false;
}
}