mirror of
https://github.com/darksaid98/oxmysql.git
synced 2026-12-02 14:38:50 +00:00
refactor(web): debounce pagination to avoid callback spam
This commit is contained in:
1 parent
109344e097
commit
abe50d59e7
2 files changed
+11
-3
No files matched your search
@@ -12,7 +12,7 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { meta } from 'tinro';
|
||||
import { fetchNui } from '../../../utils/fetchNui';
|
||||
import { tablePage } from '../../../store';
|
||||
import { debouncedTablePage } from '../../../store';
|
||||
|
||||
const route = meta();
|
||||
|
||||
@@ -68,7 +68,7 @@
|
||||
$: {
|
||||
fetchNui('fetchResource', {
|
||||
resource: route.params.resource,
|
||||
pageIndex: $tablePage,
|
||||
pageIndex: $debouncedTablePage,
|
||||
sortBy: sorting,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { writable } from 'svelte/store';
|
||||
import { derived, writable } from 'svelte/store';
|
||||
|
||||
export interface QueryData {
|
||||
date: number;
|
||||
@@ -20,3 +20,11 @@ export const resourceData = writable<{
|
||||
});
|
||||
|
||||
export const tablePage = writable(0);
|
||||
|
||||
let timer: NodeJS.Timer;
|
||||
export const debouncedTablePage = derived(tablePage, ($tablePage, set) => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(() => {
|
||||
set($tablePage);
|
||||
}, 300);
|
||||
});
|
||||
Reference in new issue
Block a user