From 3d04fd1ac9c6460dbaa57e2226f48cc4fd258d1c Mon Sep 17 00:00:00 2001 From: azro Date: Fri, 2 Dec 2022 09:46:05 +0100 Subject: [PATCH] Try to use only hook useResponsiveMap --- components/_util/__tests__/responsiveObserve.test.ts | 4 ++-- components/_util/responsiveObserve.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/_util/__tests__/responsiveObserve.test.ts b/components/_util/__tests__/responsiveObserve.test.ts index 6ab86ec802ea..27bc6694b380 100644 --- a/components/_util/__tests__/responsiveObserve.test.ts +++ b/components/_util/__tests__/responsiveObserve.test.ts @@ -1,8 +1,8 @@ -import ResponsiveObserve, { responsiveMap } from '../responsiveObserve'; +import ResponsiveObserve, { useResponsiveMap } from '../responsiveObserve'; describe('Test ResponsiveObserve', () => { it('test ResponsiveObserve subscribe and unsubscribe', () => { - const { xs } = responsiveMap; + const { xs } = useResponsiveMap(); const subscribeFunc = jest.fn(); const token = ResponsiveObserve.subscribe(subscribeFunc); expect(ResponsiveObserve.matchHandlers[xs].mql.matches).toBeTruthy(); diff --git a/components/_util/responsiveObserve.ts b/components/_util/responsiveObserve.ts index 056edd1b5fc9..86d5856d328a 100644 --- a/components/_util/responsiveObserve.ts +++ b/components/_util/responsiveObserve.ts @@ -20,8 +20,6 @@ const useResponsiveMap = (): BreakpointMap => { } as BreakpointMap; }; -export const responsiveMap: BreakpointMap = useResponsiveMap(); - type SubscribeFunc = (screens: ScreenMap) => void; const subscribers = new Map(); let subUid = -1; @@ -51,6 +49,7 @@ const responsiveObserve = { if (!subscribers.size) this.unregister(); }, unregister() { + const responsiveMap: BreakpointMap = useResponsiveMap(); Object.keys(responsiveMap).forEach((screen: Breakpoint) => { const matchMediaQuery = responsiveMap[screen]; const handler = this.matchHandlers[matchMediaQuery]; @@ -59,6 +58,7 @@ const responsiveObserve = { subscribers.clear(); }, register() { + const responsiveMap: BreakpointMap = useResponsiveMap(); Object.keys(responsiveMap).forEach((screen: Breakpoint) => { const matchMediaQuery = responsiveMap[screen]; const listener = ({ matches }: { matches: boolean }) => {