Skip to content

Commit

Permalink
navigate immedietely if debounce is set to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
paoloricciuti committed Dec 19, 2023
1 parent 8b31648 commit 9af4ffb
Showing 1 changed file with 38 additions and 32 deletions.
70 changes: 38 additions & 32 deletions src/lib/sveltekit-search-params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,22 +214,25 @@ export function queryParameters<T extends object>(
clearTimeout(debouncedTimeouts.get('queryParameters'));
if (browser) {
overrides.set(value);
debouncedTimeouts.set(
'queryParameters',
setTimeout(
async () => {
if (sort) {
query.sort();
}
await goto(
`?${query}${hash}`,
pushHistory ? GOTO_OPTIONS_PUSH : GOTO_OPTIONS,
);
overrides.set({});
},
changeImmediately ? 0 : debounceHistory,
),
);
// eslint-disable-next-line no-inner-declarations
async function navigate() {
if (sort) {
query.sort();
}
await goto(
`?${query}${hash}`,
pushHistory ? GOTO_OPTIONS_PUSH : GOTO_OPTIONS,
);
overrides.set({});
}
if (changeImmediately || debounceHistory === 0) {
navigate();
} else {
debouncedTimeouts.set(
'queryParameters',
setTimeout(navigate, debounceHistory),
);
}
}
batchedUpdates.clear();
});
Expand Down Expand Up @@ -305,22 +308,25 @@ export function queryParam<T = string>(
clearTimeout(debouncedTimeouts.get(name));
if (browser) {
override.set(value);
debouncedTimeouts.set(
name,
setTimeout(
async () => {
if (sort) {
query.sort();
}
await goto(
`?${query}${hash}`,
pushHistory ? GOTO_OPTIONS_PUSH : GOTO_OPTIONS,
);
override.set(null);
},
changeImmediately ? 0 : debounceHistory,
),
);
// eslint-disable-next-line no-inner-declarations
async function navigate() {
if (sort) {
query.sort();
}
await goto(
`?${query}${hash}`,
pushHistory ? GOTO_OPTIONS_PUSH : GOTO_OPTIONS,
);
override.set(null);
}
if (changeImmediately || debounceHistory === 0) {
navigate();
} else {
debouncedTimeouts.set(
name,
setTimeout(navigate, debounceHistory),
);
}
}
batchedUpdates.clear();
});
Expand Down

0 comments on commit 9af4ffb

Please sign in to comment.