Skip to content

Commit

Permalink
Try to use only hook useResponsiveMap
Browse files Browse the repository at this point in the history
  • Loading branch information
azro352 committed Dec 2, 2022
1 parent 2d9ca25 commit 3d04fd1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions 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();
Expand Down
4 changes: 2 additions & 2 deletions components/_util/responsiveObserve.ts
Expand Up @@ -20,8 +20,6 @@ const useResponsiveMap = (): BreakpointMap => {
} as BreakpointMap;
};

export const responsiveMap: BreakpointMap = useResponsiveMap();

type SubscribeFunc = (screens: ScreenMap) => void;
const subscribers = new Map<Number, SubscribeFunc>();
let subUid = -1;
Expand Down Expand Up @@ -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];
Expand All @@ -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 }) => {
Expand Down

0 comments on commit 3d04fd1

Please sign in to comment.