Skip to content

Commit

Permalink
Debounce fetchResults instead of watch
Browse files Browse the repository at this point in the history
  • Loading branch information
marySalvi committed Feb 23, 2024
1 parent 7298167 commit e1d41fa
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions web/src/use/usePaginatedResults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,24 @@ export default function usePaginatedResult<T>(
});
}

const debouncedFetchResults = debounce(fetchResults, 500);

watch([
toRef(data, 'limit'),
toRef(data, 'offset'),
], fetchResults);
], debouncedFetchResults);

watch([conditions], debounce(() => {
watch([conditions], () => {
const doFetch = data.offset === 0;
data.offset = 0;
data.limit = limit;
if (doFetch) fetchResults();
}, 500));
if (doFetch) debouncedFetchResults();
});

if (dataObjectFilter !== undefined) {
watch(dataObjectFilter, fetchResults, { deep: true });
watch(dataObjectFilter, debouncedFetchResults, { deep: true });
}
fetchResults();
debouncedFetchResults();
// ENDTODO

function setPage(newPage: number) {
Expand Down

0 comments on commit e1d41fa

Please sign in to comment.