refactor(sample-list): replace layoutManager singleton with lazy accessor
Convert the eager layoutManager singleton to getLayoutManager() (+ __resetLayoutManager for tests), so its persisted layout preference is read on first access rather than at module load. Update the model barrels and consumers (LayoutSwitch, SampleListSection, SampleList) with $derived reads; the LayoutSwitch test resolves via the accessor.
This commit is contained in:
@@ -7,7 +7,7 @@ import { ButtonGroup } from '$shared/ui';
|
||||
import { IconButton } from '$shared/ui';
|
||||
import GridIcon from '@lucide/svelte/icons/layout-grid';
|
||||
import ListIcon from '@lucide/svelte/icons/stretch-horizontal';
|
||||
import { layoutManager } from '../../model';
|
||||
import { getLayoutManager } from '../../model';
|
||||
|
||||
interface Props {
|
||||
/**
|
||||
@@ -18,18 +18,21 @@ interface Props {
|
||||
|
||||
const { class: className }: Props = $props();
|
||||
|
||||
const layoutManager = getLayoutManager();
|
||||
const mode = $derived(layoutManager.mode);
|
||||
|
||||
function handleClick() {
|
||||
layoutManager.toggleMode();
|
||||
}
|
||||
</script>
|
||||
|
||||
<ButtonGroup class={className}>
|
||||
<IconButton active={layoutManager.mode === 'list'} onclick={handleClick}>
|
||||
<IconButton active={mode === 'list'} onclick={handleClick}>
|
||||
{#snippet icon()}
|
||||
<ListIcon class="size-4" />
|
||||
{/snippet}
|
||||
</IconButton>
|
||||
<IconButton active={layoutManager.mode === 'grid'} onclick={handleClick}>
|
||||
<IconButton active={mode === 'grid'} onclick={handleClick}>
|
||||
{#snippet icon()}
|
||||
<GridIcon class="size-4" />
|
||||
{/snippet}
|
||||
|
||||
Reference in New Issue
Block a user