From 1a1b5d7b3e676c8b96faed9c6c951a9e259dcc33 Mon Sep 17 00:00:00 2001 From: Maciej Pyrc Date: Tue, 3 Dec 2024 11:44:18 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20adjusted=20keys=20co?= =?UTF-8?q?mparison?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../use-request-events/use-request-events.hooks.ts | 8 ++++---- .../use-request-events/use-request-events.types.ts | 2 +- .../helpers/use-tracked-state/use-tracked-state.hooks.ts | 4 ++-- .../helpers/use-tracked-state/use-tracked-state.types.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/react/src/helpers/use-request-events/use-request-events.hooks.ts b/packages/react/src/helpers/use-request-events/use-request-events.hooks.ts index 36d70ea5..249d4ec9 100644 --- a/packages/react/src/helpers/use-request-events/use-request-events.hooks.ts +++ b/packages/react/src/helpers/use-request-events/use-request-events.hooks.ts @@ -108,15 +108,15 @@ export const useRequestEvents = ({ // Lifecycle // ****************** - const handleGetLoadingEvent = (queueKey: string) => { + const handleGetLoadingEvent = (req: T) => { return ({ loading }: RequestLoadingEventType) => { - const isProcessing = getIsDataProcessing(); + const isProcessing = getIsDataProcessing(req.cacheKey); // When we process the cache data, we don't want to change the loading state during it // This prevents the UI from flickering with { data: null, loading: false } if (isProcessing) return; - const canDisableLoading = !loading && !dispatcher.hasRunningRequests(queueKey); + const canDisableLoading = !loading && !dispatcher.hasRunningRequests(req.queueKey); if (loading || canDisableLoading) { actions.setLoading(loading, false); } @@ -174,7 +174,7 @@ export const useRequestEvents = ({ const addCacheDataListener = (req: T) => { // Data handlers - const loadingUnmount = requestManager.events.onLoading(req.queueKey, handleGetLoadingEvent(req.queueKey)); + const loadingUnmount = requestManager.events.onLoading(req.queueKey, handleGetLoadingEvent(req)); const getResponseUnmount = cache.events.onData, ExtractErrorType, ExtractAdapterType>( req.cacheKey, setCacheData, diff --git a/packages/react/src/helpers/use-request-events/use-request-events.types.ts b/packages/react/src/helpers/use-request-events/use-request-events.types.ts index 622ca5b3..cf0bcf45 100644 --- a/packages/react/src/helpers/use-request-events/use-request-events.types.ts +++ b/packages/react/src/helpers/use-request-events/use-request-events.types.ts @@ -24,7 +24,7 @@ export type UseRequestEventsPropsType = { logger: LoggerType; actions: UseTrackedStateActions; setCacheData: (cacheData: CacheValueType, ExtractErrorType>) => void; - getIsDataProcessing: () => boolean; + getIsDataProcessing: (cacheKey: string) => boolean; }; export type UseRequestEventsActionsType = { diff --git a/packages/react/src/helpers/use-tracked-state/use-tracked-state.hooks.ts b/packages/react/src/helpers/use-tracked-state/use-tracked-state.hooks.ts index d42dc76a..ca3516ae 100644 --- a/packages/react/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +++ b/packages/react/src/helpers/use-tracked-state/use-tracked-state.hooks.ts @@ -179,8 +179,8 @@ export const useTrackedState = ({ } }; - const getIsDataProcessing = () => { - return isProcessingData.current === cacheKey; + const getIsDataProcessing = (processingCacheKey: string) => { + return isProcessingData.current === processingCacheKey; }; const setCacheData = ( diff --git a/packages/react/src/helpers/use-tracked-state/use-tracked-state.types.ts b/packages/react/src/helpers/use-tracked-state/use-tracked-state.types.ts index 29316c2c..317cc470 100644 --- a/packages/react/src/helpers/use-tracked-state/use-tracked-state.types.ts +++ b/packages/react/src/helpers/use-tracked-state/use-tracked-state.types.ts @@ -31,7 +31,7 @@ export type UseTrackedStateReturn = [ setRenderKey: (renderKey: keyof UseTrackedStateType) => void; setCacheData: (cacheData: CacheValueType, ExtractErrorType>) => void; getStaleStatus: () => boolean; - getIsDataProcessing: () => boolean; + getIsDataProcessing: (cacheKey: string) => boolean; }, ];