refactor(GetFonts): centralize filterManager/sortStore → fontStore bridge
Move the duplicated $effect blocks that mapped filterManager and sortStore into fontStore params out of Search, FontSearch and FilterControls into a single $effect.root in features/GetFonts/model/state/bindings.svelte.ts. Consumers now bind to the manager/store directly; the bridge is installed once via a side-effect import from the feature barrel.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* Bridges feature-level UI state (filterManager + sortStore) to the
|
||||
* entity-level fontStore query params.
|
||||
*
|
||||
* Centralizing this here means consumers (Search, FontSearch,
|
||||
* FilterControls, etc.) bind to the manager/store directly without
|
||||
* each repeating the same mapping effect. The bridge is a singleton
|
||||
* concern — it tracks singleton state and writes to a singleton query
|
||||
* observer, so it lives at module scope, not in any individual widget.
|
||||
*/
|
||||
|
||||
import { fontStore } from '$entities/Font';
|
||||
import { untrack } from 'svelte';
|
||||
import { mapManagerToParams } from '../../lib/mapper/mapManagerToParams';
|
||||
import { sortStore } from '../store/sortStore.svelte';
|
||||
import { filterManager } from './manager.svelte';
|
||||
|
||||
$effect.root(() => {
|
||||
/**
|
||||
* Mirror filter selections + debounced search query into fontStore params.
|
||||
* untrack the write so fontStore's internal $state reads don't feed back
|
||||
* into this effect's dependency graph.
|
||||
*/
|
||||
$effect(() => {
|
||||
const params = mapManagerToParams(filterManager);
|
||||
untrack(() => fontStore.setParams(params));
|
||||
});
|
||||
|
||||
/**
|
||||
* Mirror sort selection into fontStore.
|
||||
*/
|
||||
$effect(() => {
|
||||
const apiSort = sortStore.apiValue;
|
||||
untrack(() => fontStore.setSort(apiSort));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user