refactor(font): replace fontCatalogStore singleton with lazy getFontCatalog

Swap the eagerly-constructed fontCatalogStore singleton for a lazy
getFontCatalog() accessor (plus __resetFontCatalog for tests), so the
InfiniteQueryObserver is created on first use rather than at module load.
Update the model barrels and all consumers (FontVirtualList, SampleList,
SampleListSection) to the accessor.

Also extract createFontLoadRequestConfig from FontVirtualList: it resolves a
font's URL for a weight and returns a 0-or-1 element array, letting callers
flatMap over a list to build load requests and drop unresolvable fonts in one
pass.
This commit is contained in:
Ilia Mashkov
2026-06-01 17:24:55 +03:00
parent 39d1ce4c37
commit 10603d18bf
8 changed files with 204 additions and 49 deletions
@@ -483,8 +483,14 @@ export class FontCatalogStore {
}
}
export function createFontCatalogStore(params: FontStoreParams = {}): FontCatalogStore {
return new FontCatalogStore(params);
let _catalog: FontCatalogStore | undefined;
export function getFontCatalog(): FontCatalogStore {
return (_catalog ??= new FontCatalogStore({ limit: 50 }));
}
export const fontCatalogStore = new FontCatalogStore({ limit: 50 });
// test-only reset, so specs don't share a live observer
export function __resetFontCatalog() {
_catalog?.destroy();
_catalog = undefined;
}
+3 -5
View File
@@ -2,11 +2,9 @@
export * from './fontLifecycleManager/fontLifecycleManager.svelte';
// Paginated catalog
export {
createFontCatalogStore,
FontCatalogStore,
fontCatalogStore,
} from './fontCatalogStore/fontCatalogStore.svelte';
export { getFontCatalog } from './fontCatalogStore/fontCatalogStore.svelte';
export type { FontCatalogStore } from './fontCatalogStore/fontCatalogStore.svelte';
// Batch fetch by IDs (detail-cache seeding)
export { FontsByIdsStore } from './fontsByIdsStore/fontsByIdsStore.svelte';