Refactor alias filter handling in Svelte components to prevent unnecessary updates
- Added a check to prevent alias filter changes from triggering updates if the selected alias remains the same. - Introduced a reactive effect to apply alias changes only when the component is rendered in the browser, improving performance and clarity in data handling.
This commit is contained in:
@@ -236,6 +236,7 @@
|
||||
}
|
||||
|
||||
async function handleAliasFilterChange(nextAlias: string) {
|
||||
if (nextAlias === aliasFilter) return;
|
||||
aliasFilter = nextAlias;
|
||||
await applyAliasIfChanged(nextAlias);
|
||||
}
|
||||
@@ -251,6 +252,12 @@ async function handleAliasFilterChange(nextAlias: string) {
|
||||
void load();
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
const nextAlias = aliasFilter;
|
||||
void applyAliasIfChanged(nextAlias);
|
||||
});
|
||||
|
||||
let staleSeconds = $derived.by(() =>
|
||||
lastSuccessAtMs == null ? null : Math.max(0, Math.floor((nowMs - lastSuccessAtMs) / 1000))
|
||||
);
|
||||
|
||||
@@ -135,6 +135,7 @@
|
||||
}
|
||||
|
||||
async function handleAliasFilterChange(nextAlias: string) {
|
||||
if (nextAlias === aliasFilter) return;
|
||||
aliasFilter = nextAlias;
|
||||
await applyAliasIfChanged(nextAlias);
|
||||
}
|
||||
@@ -151,6 +152,12 @@
|
||||
void load();
|
||||
});
|
||||
|
||||
$effect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
const nextAlias = aliasFilter;
|
||||
void applyAliasIfChanged(nextAlias);
|
||||
});
|
||||
|
||||
let staleSeconds = $derived.by(() =>
|
||||
lastSuccessAtMs == null ? null : Math.max(0, Math.floor((nowMs - lastSuccessAtMs) / 1000))
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user