refactor(filters): replace filter/sort store singletons with lazy accessors

Convert appliedFilterStore, availableFilterStore and sortStore from eager
module-level singletons to getAppliedFilterStore/getAvailableFilterStore/
getSortStore lazy accessors (+ __reset* helpers for tests), so the
availableFilterStore QueryObserver is built on first use rather than at import.

Update barrels, the startFilterBindings bridge, and all consumers. Reactive
reads in components are wrapped in $derived; two-way bind:value targets resolve
the accessor once and bind directly (a $derived is read-only).
This commit is contained in:
Ilia Mashkov
2026-06-01 18:37:18 +03:00
parent 9780ff9358
commit 0b675635b3
13 changed files with 107 additions and 46 deletions
@@ -5,8 +5,10 @@
propagates the value into fontCatalogStore.
-->
<script lang="ts">
import { appliedFilterStore } from '$features/FilterAndSortFonts';
import { getAppliedFilterStore } from '$features/FilterAndSortFonts';
import { SearchBar } from '$shared/ui';
const appliedFilterStore = getAppliedFilterStore();
</script>
<div class="p-6 border-b border-subtle">
@@ -1,4 +1,4 @@
import { appliedFilterStore } from '$features/FilterAndSortFonts';
import { getAppliedFilterStore } from '$features/FilterAndSortFonts';
import {
render,
screen,
@@ -7,7 +7,7 @@ import Search from './Search.svelte';
describe('Search', () => {
beforeEach(() => {
appliedFilterStore.queryValue = '';
getAppliedFilterStore().queryValue = '';
});
describe('Rendering', () => {
@@ -24,7 +24,7 @@ describe('Search', () => {
describe('Value binding', () => {
it('reflects appliedFilterStore.queryValue as initial value', () => {
appliedFilterStore.queryValue = 'Inter';
getAppliedFilterStore().queryValue = 'Inter';
render(Search);
expect(screen.getByRole('textbox')).toHaveValue('Inter');
});