Skip to content

Commit

Permalink
version: 2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonYong committed Jun 7, 2024
1 parent 1bd1ba4 commit dfe9f26
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/hooks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "vue-hooks-plus",
"version": "2.1.0",
"version": "2.2.0",
"description": "Vue hooks library",
"files": [
"dist",
Expand Down
2 changes: 1 addition & 1 deletion packages/use-request/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@vue-hooks-plus/use-request",
"version": "2.1.0",
"version": "2.2.0",
"description": "Vue use-request hooks library",
"files": [
"dist",
Expand Down
19 changes: 5 additions & 14 deletions packages/use-request/src/plugins/usePollingPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import { unref, ref, watchEffect } from "vue";
import type { UseRequestPlugin, Interval } from "../types";
import type { UseRequestPlugin, Timeout } from "../types";
import isDocumentVisible from "../utils/isDocumentVisible";
import subscribeReVisible from "../utils/subscribeReVisible";

const usePollingPlugin: UseRequestPlugin<unknown, unknown[]> = (
fetchInstance,
{ pollingInterval, pollingWhenHidden = true, pollingErrorRetryCount = -1 }
) => {
const timerRef = ref<Interval>();
let timeouter:Timeout
const unsubscribeRef = ref<() => void>();
const countRef = ref<number>(0);



const stopPolling = () => {
if (timerRef.value) {
clearInterval(timerRef.value);
if (timeouter) {
clearTimeout(timeouter);
}
unsubscribeRef.value?.();
};
Expand Down Expand Up @@ -47,7 +47,7 @@ const usePollingPlugin: UseRequestPlugin<unknown, unknown[]> = (
// When an error occurs, the request is not repeated after pollingErrorRetryCount retries
(pollingErrorRetryCount !== -1 && countRef.value <= pollingErrorRetryCount)
) {
timerRef.value = setTimeout(() => {
timeouter = setTimeout(() => {
// if pollingWhenHidden = false && document is hidden, then stop polling and subscribe revisible
if (!pollingWhenHidden && !isDocumentVisible()) {
unsubscribeRef.value = subscribeReVisible(() => {
Expand All @@ -60,15 +60,6 @@ const usePollingPlugin: UseRequestPlugin<unknown, unknown[]> = (
} else {
countRef.value = 0;
}
// if (!pollingWhenHidden && !isDocumentVisible()) {
// unsubscribeRef.value = subscribeReVisible(() => {
// fetchInstance.refresh();
// });
// return;
// }
// timerRef.value = setInterval(() => {
// fetchInstance.refresh();
// },unref(pollingInterval));
},
onCancel: () => {
stopPolling();
Expand Down

0 comments on commit dfe9f26

Please sign in to comment.