Skip to content

Commit

Permalink
chore: remove canUseDom with isBrowser (alibaba#1753)
Browse files Browse the repository at this point in the history
Co-authored-by: huangcheng <huangcheng.lq@bytedance.com>
  • Loading branch information
chenym1992 and hchlq authored Jul 19, 2022
1 parent 472dd83 commit d09c9d8
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/hooks/src/useRequest/src/utils/isDocumentVisible.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import canUseDom from '../../../utils/canUseDom';
import isBrowser from '../../../utils/isBrowser';

export default function isDocumentVisible(): boolean {
if (canUseDom()) {
if (isBrowser) {
return document.visibilityState !== 'hidden';
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useRequest/src/utils/isOnline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import canUseDom from '../../../utils/canUseDom';
import isBrowser from '../../../utils/isBrowser';

export default function isOnline(): boolean {
if (canUseDom() && typeof navigator.onLine !== 'undefined') {
if (isBrowser && typeof navigator.onLine !== 'undefined') {
return navigator.onLine;
}
return true;
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useRequest/src/utils/subscribeFocus.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// from swr
import canUseDom from '../../../utils/canUseDom';
import isBrowser from '../../../utils/isBrowser';
import isDocumentVisible from './isDocumentVisible';
import isOnline from './isOnline';

Expand All @@ -13,7 +13,7 @@ function subscribe(listener: () => void) {
};
}

if (canUseDom()) {
if (isBrowser) {
const revalidate = () => {
if (!isDocumentVisible() || !isOnline()) return;
for (let i = 0; i < listeners.length; i++) {
Expand Down
4 changes: 2 additions & 2 deletions packages/hooks/src/useRequest/src/utils/subscribeReVisible.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import canUseDom from '../../../utils/canUseDom';
import isBrowser from '../../../utils/isBrowser';
import isDocumentVisible from './isDocumentVisible';

const listeners: any[] = [];
Expand All @@ -11,7 +11,7 @@ function subscribe(listener: () => void) {
};
}

if (canUseDom()) {
if (isBrowser) {
const revalidate = () => {
if (!isDocumentVisible()) return;
for (let i = 0; i < listeners.length; i++) {
Expand Down
3 changes: 0 additions & 3 deletions packages/hooks/src/utils/canUseDom.ts

This file was deleted.

0 comments on commit d09c9d8

Please sign in to comment.