mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
catalog: migrate remaining 36 useCatalog() consumers to the three filters
Replaces every direct call to the deprecated useCatalog() shim with the targeted filter(s) (useCatalogData / useCatalogUiState / useCatalogActions). Each consumer now subscribes only to the slice it actually reads, which restores React Compiler memoization and stops catalog-wide re-renders whenever an unrelated key changes. Removes the now-unused useCatalog shim from useCatalog.ts and the shim-specific case in tests/useCatalog.filters.test.tsx. The "all four hooks observe the same singleton" test becomes "all three filters", since there is no shim left to compare against. useCatalogFavorites swaps its internal useCatalog() call for useCatalogUiState() (currentType lives in the UI slice). Updates CLAUDE.md and docs/ARCHITECTURE.md to reflect that all 48 historical consumers are migrated and the shim is gone. Vitest: 162/162 (was 163 — minus the deprecated-shim contract case).
This commit is contained in:
@@ -1060,11 +1060,3 @@ export const useCatalogActions = () =>
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Deprecated. Kept so the 48 existing consumers compile unchanged —
|
||||
* incrementally migrate them to `useCatalogData` / `useCatalogUiState`
|
||||
* / `useCatalogActions` and remove this shim once the call sites are
|
||||
* gone. Mirrors the same `useBetween` singleton, so behavior is
|
||||
* identical.
|
||||
*/
|
||||
export const useCatalog = () => useBetween(useCatalogStore);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useBetween } from 'use-between';
|
||||
import { CatalogType } from '../../api';
|
||||
import { useCatalog } from './useCatalog';
|
||||
import { useCatalogUiState } from './useCatalog';
|
||||
import { getOffersStorageKey, getPagesStorageKey, IFavoriteOffer, LEGACY_STORAGE_KEY_OFFERS, LEGACY_STORAGE_KEY_PAGES, normalizeCatalogType, parseOffers, parsePages } from './useCatalogFavorites.helpers';
|
||||
|
||||
export type { IFavoriteOffer } from './useCatalogFavorites.helpers';
|
||||
@@ -66,7 +66,7 @@ const writePages = (catalogType: string, ids: number[]) =>
|
||||
|
||||
const useCatalogFavoritesState = () =>
|
||||
{
|
||||
const { currentType = CatalogType.NORMAL } = useCatalog();
|
||||
const { currentType = CatalogType.NORMAL } = useCatalogUiState();
|
||||
const catalogType = normalizeCatalogType(currentType);
|
||||
const [ favoriteOffersByType, setFavoriteOffersByType ] = useState<Record<string, IFavoriteOffer[]>>({
|
||||
[CatalogType.NORMAL]: [],
|
||||
|
||||
Reference in New Issue
Block a user