Skip to content

Commit dfe9f26

Browse files
committed
version: 2.2.0
1 parent 1bd1ba4 commit dfe9f26

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

packages/hooks/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-hooks-plus",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "Vue hooks library",
55
"files": [
66
"dist",

packages/use-request/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@vue-hooks-plus/use-request",
3-
"version": "2.1.0",
3+
"version": "2.2.0",
44
"description": "Vue use-request hooks library",
55
"files": [
66
"dist",

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
import { unref, ref, watchEffect } from "vue";
2-
import type { UseRequestPlugin, Interval } from "../types";
2+
import type { UseRequestPlugin, Timeout } from "../types";
33
import isDocumentVisible from "../utils/isDocumentVisible";
44
import subscribeReVisible from "../utils/subscribeReVisible";
55

66
const usePollingPlugin: UseRequestPlugin<unknown, unknown[]> = (
77
fetchInstance,
88
{ pollingInterval, pollingWhenHidden = true, pollingErrorRetryCount = -1 }
99
) => {
10-
const timerRef = ref<Interval>();
10+
let timeouter:Timeout
1111
const unsubscribeRef = ref<() => void>();
1212
const countRef = ref<number>(0);
1313

1414

1515

1616
const stopPolling = () => {
17-
if (timerRef.value) {
18-
clearInterval(timerRef.value);
17+
if (timeouter) {
18+
clearTimeout(timeouter);
1919
}
2020
unsubscribeRef.value?.();
2121
};
@@ -47,7 +47,7 @@ const usePollingPlugin: UseRequestPlugin<unknown, unknown[]> = (
4747
// When an error occurs, the request is not repeated after pollingErrorRetryCount retries
4848
(pollingErrorRetryCount !== -1 && countRef.value <= pollingErrorRetryCount)
4949
) {
50-
timerRef.value = setTimeout(() => {
50+
timeouter = setTimeout(() => {
5151
// if pollingWhenHidden = false && document is hidden, then stop polling and subscribe revisible
5252
if (!pollingWhenHidden && !isDocumentVisible()) {
5353
unsubscribeRef.value = subscribeReVisible(() => {
@@ -60,15 +60,6 @@ const usePollingPlugin: UseRequestPlugin<unknown, unknown[]> = (
6060
} else {
6161
countRef.value = 0;
6262
}
63-
// if (!pollingWhenHidden && !isDocumentVisible()) {
64-
// unsubscribeRef.value = subscribeReVisible(() => {
65-
// fetchInstance.refresh();
66-
// });
67-
// return;
68-
// }
69-
// timerRef.value = setInterval(() => {
70-
// fetchInstance.refresh();
71-
// },unref(pollingInterval));
7263
},
7364
onCancel: () => {
7465
stopPolling();

0 commit comments

Comments
 (0)