refactor: extract magic constants — wave 1 (UX, API, storage)
- Use existing MULTIPLIER_S/M/L from \$entities/Font in SliderArea instead of inlining the 0.5/0.75/1 literals (constants already existed but were duplicated at the call site). - Centralize API base URL in \$shared/api/endpoints.ts (was duplicated between proxyFonts and FilterAndSortFonts filters api). - Promote every 'glyphdiff:...' localStorage key to a named module-level STORAGE_KEY constant. Test files now import the source constant rather than redeclaring it (eliminates silent-typo divergence risk).
This commit is contained in:
+12
-2
@@ -297,6 +297,16 @@ export class TypographySettingsStore {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Default factory storage key — used when a caller doesn't pass one.
|
||||
*/
|
||||
const DEFAULT_STORAGE_KEY = 'glyphdiff:typography';
|
||||
|
||||
/**
|
||||
* Storage key used by the app-wide singleton (scoped to comparison view).
|
||||
*/
|
||||
const COMPARISON_STORAGE_KEY = 'glyphdiff:comparison:typography';
|
||||
|
||||
/**
|
||||
* Creates a typography control manager
|
||||
*
|
||||
@@ -306,7 +316,7 @@ export class TypographySettingsStore {
|
||||
*/
|
||||
export function createTypographySettingsStore(
|
||||
configs: ControlModel<ControlId>[],
|
||||
storageId: string = 'glyphdiff:typography',
|
||||
storageId: string = DEFAULT_STORAGE_KEY,
|
||||
) {
|
||||
const storage = createPersistentStore<TypographySettings>(storageId, {
|
||||
fontSize: DEFAULT_FONT_SIZE,
|
||||
@@ -322,5 +332,5 @@ export function createTypographySettingsStore(
|
||||
*/
|
||||
export const typographySettingsStore = createTypographySettingsStore(
|
||||
DEFAULT_TYPOGRAPHY_CONTROLS_DATA,
|
||||
'glyphdiff:comparison:typography',
|
||||
COMPARISON_STORAGE_KEY,
|
||||
);
|
||||
|
||||
@@ -30,6 +30,8 @@
|
||||
|
||||
import { createPersistentStore } from '$shared/lib';
|
||||
|
||||
export const STORAGE_KEY = 'glyphdiff:theme';
|
||||
|
||||
type Theme = 'light' | 'dark';
|
||||
type ThemeSource = 'system' | 'user';
|
||||
|
||||
@@ -56,7 +58,7 @@ class ThemeManager {
|
||||
/**
|
||||
* Persistent storage for user's theme preference
|
||||
*/
|
||||
#store = createPersistentStore<Theme | null>('glyphdiff:theme', null);
|
||||
#store = createPersistentStore<Theme | null>(STORAGE_KEY, null);
|
||||
/**
|
||||
* Bound handler for system theme change events
|
||||
*/
|
||||
|
||||
@@ -40,8 +40,7 @@ import { ThemeManager } from './ThemeManager.svelte';
|
||||
* - MediaQueryList listener management
|
||||
*/
|
||||
|
||||
// Storage key used by ThemeManager
|
||||
const STORAGE_KEY = 'glyphdiff:theme';
|
||||
import { STORAGE_KEY } from './ThemeManager.svelte';
|
||||
|
||||
// Helper type for MediaQueryList event handler
|
||||
type MediaQueryListCallback = (this: MediaQueryList, ev: MediaQueryListEvent) => void;
|
||||
|
||||
@@ -8,8 +8,9 @@
|
||||
*/
|
||||
|
||||
import { api } from '$shared/api/api';
|
||||
import { API_ENDPOINTS } from '$shared/api/endpoints';
|
||||
|
||||
const PROXY_API_URL = 'https://api.glyphdiff.com/api/v1/filters' as const;
|
||||
const PROXY_API_URL = API_ENDPOINTS.filters;
|
||||
|
||||
/**
|
||||
* Filter metadata type from backend
|
||||
|
||||
Reference in New Issue
Block a user