Skip to content

Commit a124393

Browse files
committed
chore(use-request): remove circular dependency taro-hooks
1 parent 9592ce2 commit a124393

File tree

6 files changed

+53
-8
lines changed

6 files changed

+53
-8
lines changed

packages/use-request/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@
3838
"dependencies": {
3939
"@taro-hooks/ahooks": "workspace:*",
4040
"@taro-hooks/shared": "workspace:*",
41-
"lodash-wechat": "^1.0.0",
42-
"taro-hooks": "workspace:*"
41+
"lodash-wechat": "^1.0.0"
4342
},
4443
"peerDependencies": {
4544
"@tarojs/taro": ">=3.4.x",

packages/use-request/src/plugins/usePollingPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useRef } from '@taro-hooks/core';
22
import { useUpdateEffect } from '@taro-hooks/ahooks';
33
import { escapeState } from '@taro-hooks/shared';
4-
import { useVisible } from 'taro-hooks';
4+
import useVisible from '../useVisible';
55
import type { Plugin, Timeout } from '../types';
66
import subscribeReVisible from '../utils/subscribeReVisible';
77

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { useDidHide } from '@tarojs/taro';
2+
import { useEffect, useState } from '@taro-hooks/core';
3+
4+
function useVisible(): boolean {
5+
const [visible, changeVisible] = useState<boolean>(true);
6+
const listenVisible = () => {
7+
const visibleState = document.visibilityState;
8+
changeVisible(visibleState === 'visible');
9+
};
10+
11+
useEffect(() => {
12+
window.addEventListener('visibilitychange', listenVisible, false);
13+
window.addEventListener('focus', listenVisible, false);
14+
window.addEventListener('blur', listenVisible, false);
15+
16+
return () => {
17+
window.removeEventListener('visibilitychange', listenVisible, false);
18+
window.removeEventListener('focus', listenVisible, false);
19+
window.removeEventListener('blur', listenVisible, false);
20+
};
21+
}, []);
22+
23+
// unmount change false
24+
useDidHide(() => {
25+
changeVisible(false);
26+
});
27+
28+
return visible;
29+
}
30+
31+
export default useVisible;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { useDidHide, useDidShow } from '@tarojs/taro';
2+
import { useState } from '@taro-hooks/core';
3+
4+
function useVisible(): boolean {
5+
const [visible, changeVisible] = useState<boolean>(true);
6+
7+
useDidShow(() => {
8+
changeVisible(true);
9+
});
10+
11+
useDidHide(() => {
12+
changeVisible(false);
13+
});
14+
15+
return visible;
16+
}
17+
18+
export default useVisible;

packages/use-request/src/utils/subscribeReVisible.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { escapeState } from '@taro-hooks/shared';
22
import { useEffect } from '@taro-hooks/core';
3-
import { useVisible } from 'taro-hooks';
3+
import useVisible from '../useVisible';
44

55
const listeners: any[] = [];
66

pnpm-lock.yaml

Lines changed: 1 addition & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)