refactor(font): expose stores via model segment, not the top barrel
Re-exporting the store singletons (fontCatalogStore, fontLifecycleManager, FontsByIdsStore) through entities/Font/index.ts meant every consumer of the barrel eager-instantiated stores and pulled @tanstack/query-core — in dev, test, and as retained code. Drop the store re-export from the top barrel; keep the pure surface (types, constants, domain, lib, ui) there for convenience. Consumers that need stores import $entities/Font/model. Aligns with the BaseQueryStore carve-out: barrel by default, segment path when it would drag a heavy or side-effectful dependency.
This commit is contained in:
@@ -1,8 +1,21 @@
|
|||||||
export * from './api';
|
export * from './api';
|
||||||
export * from './domain';
|
export * from './domain';
|
||||||
export * from './lib';
|
export * from './lib';
|
||||||
export * from './model';
|
|
||||||
export * from './ui';
|
export * from './ui';
|
||||||
|
|
||||||
|
// Pure model surface (types + constants) is part of the convenient top-level
|
||||||
|
// API. Stateful stores are deliberately excluded — see below.
|
||||||
|
export * from './model/const/const';
|
||||||
|
export * from './model/types';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Stores (`fontCatalogStore`, `fontLifecycleManager`, `FontsByIdsStore`) are
|
||||||
|
* intentionally NOT re-exported here. They instantiate module-level singletons
|
||||||
|
* and pull `@tanstack/query-core`, so funneling them through this barrel would
|
||||||
|
* make every consumer of `$entities/Font` eager-instantiate stores (and break
|
||||||
|
* tree-shaking / test init-order). Import them via the model segment:
|
||||||
|
* import { fontCatalogStore } from '$entities/Font/model';
|
||||||
|
*/
|
||||||
|
|
||||||
// `./testing` is intentionally not re-exported: fixtures must not leak into the
|
// `./testing` is intentionally not re-exported: fixtures must not leak into the
|
||||||
// production public API. Import them via `$entities/Font/testing`.
|
// production public API. Import them via `$entities/Font/testing`.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
* observer, so it lives at module scope, not in any individual widget.
|
* observer, so it lives at module scope, not in any individual widget.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { fontCatalogStore } from '$entities/Font';
|
import { fontCatalogStore } from '$entities/Font/model';
|
||||||
import { untrack } from 'svelte';
|
import { untrack } from 'svelte';
|
||||||
import { mapAppliedFiltersToParams } from '../../lib/mapper/mapAppliedFiltersToParams';
|
import { mapAppliedFiltersToParams } from '../../lib/mapper/mapAppliedFiltersToParams';
|
||||||
import { appliedFilterStore } from './appliedFilterStore/appliedFilterStore.svelte';
|
import { appliedFilterStore } from './appliedFilterStore/appliedFilterStore.svelte';
|
||||||
|
|||||||
@@ -15,12 +15,14 @@
|
|||||||
|
|
||||||
import {
|
import {
|
||||||
type FontLoadRequestConfig,
|
type FontLoadRequestConfig,
|
||||||
FontsByIdsStore,
|
|
||||||
type UnifiedFont,
|
type UnifiedFont,
|
||||||
fontCatalogStore,
|
|
||||||
fontLifecycleManager,
|
|
||||||
getFontUrl,
|
getFontUrl,
|
||||||
} from '$entities/Font';
|
} from '$entities/Font';
|
||||||
|
import {
|
||||||
|
FontsByIdsStore,
|
||||||
|
fontCatalogStore,
|
||||||
|
fontLifecycleManager,
|
||||||
|
} from '$entities/Font/model';
|
||||||
import { typographySettingsStore } from '$features/AdjustTypography/model';
|
import { typographySettingsStore } from '$features/AdjustTypography/model';
|
||||||
import { createPersistentStore } from '$shared/lib';
|
import { createPersistentStore } from '$shared/lib';
|
||||||
import { untrack } from 'svelte';
|
import { untrack } from 'svelte';
|
||||||
|
|||||||
@@ -53,6 +53,16 @@ vi.mock('$shared/lib/helpers/createPersistentStore/createPersistentStore.svelte'
|
|||||||
|
|
||||||
vi.mock('$entities/Font', async importOriginal => {
|
vi.mock('$entities/Font', async importOriginal => {
|
||||||
const actual = await importOriginal<typeof import('$entities/Font')>();
|
const actual = await importOriginal<typeof import('$entities/Font')>();
|
||||||
|
return {
|
||||||
|
...actual,
|
||||||
|
getFontUrl: vi.fn(() => 'https://example.com/font.woff2'),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
// Stores moved behind the model segment; mock them there. FontsByIdsStore is
|
||||||
|
// intentionally left real (spread from actual) so $state reactivity works.
|
||||||
|
vi.mock('$entities/Font/model', async importOriginal => {
|
||||||
|
const actual = await importOriginal<typeof import('$entities/Font/model')>();
|
||||||
return {
|
return {
|
||||||
...actual,
|
...actual,
|
||||||
fontCatalogStore: { fonts: [] },
|
fontCatalogStore: { fonts: [] },
|
||||||
@@ -63,7 +73,6 @@ vi.mock('$entities/Font', async importOriginal => {
|
|||||||
getFontStatus: vi.fn(),
|
getFontStatus: vi.fn(),
|
||||||
ready: vi.fn(() => Promise.resolve()),
|
ready: vi.fn(() => Promise.resolve()),
|
||||||
},
|
},
|
||||||
getFontUrl: vi.fn(() => 'https://example.com/font.woff2'),
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -84,11 +93,11 @@ vi.mock('$features/AdjustTypography/model', () => ({
|
|||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
import * as proxyFonts from '$entities/Font/api/proxy/proxyFonts';
|
||||||
import {
|
import {
|
||||||
fontCatalogStore,
|
fontCatalogStore,
|
||||||
fontLifecycleManager,
|
fontLifecycleManager,
|
||||||
} from '$entities/Font';
|
} from '$entities/Font/model';
|
||||||
import * as proxyFonts from '$entities/Font/api/proxy/proxyFonts';
|
|
||||||
import { ComparisonStore } from './comparisonStore.svelte';
|
import { ComparisonStore } from './comparisonStore.svelte';
|
||||||
|
|
||||||
describe('ComparisonStore', () => {
|
describe('ComparisonStore', () => {
|
||||||
|
|||||||
@@ -9,9 +9,11 @@ import {
|
|||||||
FontVirtualList,
|
FontVirtualList,
|
||||||
type UnifiedFont,
|
type UnifiedFont,
|
||||||
VIRTUAL_INDEX_NOT_LOADED,
|
VIRTUAL_INDEX_NOT_LOADED,
|
||||||
|
} from '$entities/Font';
|
||||||
|
import {
|
||||||
fontCatalogStore,
|
fontCatalogStore,
|
||||||
fontLifecycleManager,
|
fontLifecycleManager,
|
||||||
} from '$entities/Font';
|
} from '$entities/Font/model';
|
||||||
import { getSkeletonWidth } from '$shared/lib/utils';
|
import { getSkeletonWidth } from '$shared/lib/utils';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
|
|||||||
@@ -8,9 +8,11 @@
|
|||||||
import {
|
import {
|
||||||
FontVirtualList,
|
FontVirtualList,
|
||||||
createFontRowSizeResolver,
|
createFontRowSizeResolver,
|
||||||
|
} from '$entities/Font';
|
||||||
|
import {
|
||||||
fontCatalogStore,
|
fontCatalogStore,
|
||||||
fontLifecycleManager,
|
fontLifecycleManager,
|
||||||
} from '$entities/Font';
|
} from '$entities/Font/model';
|
||||||
import {
|
import {
|
||||||
TypographyMenu,
|
TypographyMenu,
|
||||||
typographySettingsStore,
|
typographySettingsStore,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
Wraps SampleList with a Section component
|
Wraps SampleList with a Section component
|
||||||
-->
|
-->
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { fontCatalogStore } from '$entities/Font';
|
import { fontCatalogStore } from '$entities/Font/model';
|
||||||
import { NavigationWrapper } from '$features/Breadcrumb';
|
import { NavigationWrapper } from '$features/Breadcrumb';
|
||||||
import type { ResponsiveManager } from '$shared/lib';
|
import type { ResponsiveManager } from '$shared/lib';
|
||||||
import { cn } from '$shared/lib';
|
import { cn } from '$shared/lib';
|
||||||
|
|||||||
Reference in New Issue
Block a user