Skip to content

Commit

Permalink
feat: replace utils library
Browse files Browse the repository at this point in the history
  • Loading branch information
wangxingkang committed Aug 29, 2022
1 parent d3f1cb1 commit 3989c35
Show file tree
Hide file tree
Showing 35 changed files with 77 additions and 93 deletions.
2 changes: 1 addition & 1 deletion hooks/useClickAway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-latest": "0.2.4"
},
Expand Down
2 changes: 1 addition & 1 deletion hooks/useControllableValue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/use-memoized-fn": "0.2.5",
"@pansy/use-update": "0.2.4"
},
Expand Down
2 changes: 1 addition & 1 deletion hooks/useCookieState/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/use-memoized-fn": "0.2.5",
"@types/js-cookie": "^2.x.x",
"js-cookie": "^2.x.x"
Expand Down
1 change: 1 addition & 0 deletions hooks/useCreation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0"
},
"publishConfig": {
Expand Down
2 changes: 1 addition & 1 deletion hooks/useCreation/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DependencyList } from 'react';
import { useRef } from 'react';
import { depsAreSame } from '@pansy/hook-utils';
import { depsAreSame } from '@pansy/shared/react';

export function useCreation<T>(factory: () => T, deps: DependencyList) {
const { current } = useRef({
Expand Down
1 change: 1 addition & 0 deletions hooks/useDocumentVisibility/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-event-listener": "0.2.8"
},
Expand Down
4 changes: 2 additions & 2 deletions hooks/useDocumentVisibility/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useState } from 'react';
import { useEventListener } from '@pansy/use-event-listener';
import { isBrowser } from '@pansy/hook-utils';
import { isBrowser } from '@pansy/shared';

type VisibilityState = 'hidden' | 'visible' | 'prerender' | undefined;

Expand All @@ -14,7 +14,7 @@ const getVisibility = () => {
* 监听页面是否可见
* @returns
*/
export function useDocumentVisibility(): VisibilityState {
export function useDocumentVisibility(): VisibilityState {
const [documentVisibility, setDocumentVisibility] = useState(() => getVisibility());

useEventListener(
Expand Down
2 changes: 1 addition & 1 deletion hooks/useEventListener/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-latest": "0.2.4"
},
Expand Down
2 changes: 1 addition & 1 deletion hooks/useHover/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/use-boolean": "0.2.5",
"@pansy/use-event-listener": "0.2.8"
},
Expand Down
2 changes: 1 addition & 1 deletion hooks/useInViewport/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0",
"intersection-observer": "^0.12.0"
},
Expand Down
2 changes: 1 addition & 1 deletion hooks/useKeyPress/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-latest": "0.2.4"
},
Expand Down
1 change: 1 addition & 0 deletions hooks/useLocalStorageState/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0"
},
"publishConfig": {
Expand Down
3 changes: 2 additions & 1 deletion hooks/useLocalStorageState/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createUseStorageState, isBrowser } from '@pansy/hook-utils';
import { createUseStorageState } from '@pansy/hook-utils';
import { isBrowser } from '@pansy/shared';

/**
* 将状态存储在 localStorage 中的 Hook
Expand Down
2 changes: 1 addition & 1 deletion hooks/useMouse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/use-event-listener": "0.2.8",
"@pansy/use-raf-state": "0.2.5"
},
Expand Down
2 changes: 1 addition & 1 deletion hooks/useRequest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-creation": "0.1.4",
"@pansy/use-latest": "0.2.4",
Expand Down
4 changes: 2 additions & 2 deletions hooks/useRequest/src/utils/isDocumentVisible.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { canUseDom } from '@pansy/hook-utils';
import { isBrowser } from '@pansy/shared';

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

export 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 hooks/useRequest/src/utils/subscribeFocus.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { canUseDom } from '@pansy/hook-utils';
import { isBrowser } from '@pansy/shared';

import { isDocumentVisible } from './isDocumentVisible';
import { isOnline } from './isOnline';
Expand All @@ -13,7 +13,7 @@ export function subscribeFocus(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 hooks/useRequest/src/utils/subscribeReVisible.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { canUseDom } from '@pansy/hook-utils';
import { isBrowser } from '@pansy/shared';

import { isDocumentVisible, } from './isDocumentVisible';

Expand All @@ -12,7 +12,7 @@ export function subscribeReVisible(listener: () => void) {
};
}

if (canUseDom()) {
if (isBrowser) {
const revalidate = () => {
if (!isDocumentVisible()) return;
for (let i = 0; i < listeners.length; i++) {
Expand Down
2 changes: 1 addition & 1 deletion hooks/useScroll/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@pansy/hook-utils": "0.3.0",
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/use-latest": "0.2.4",
"@pansy/use-raf-state": "0.2.5"
},
Expand Down
2 changes: 1 addition & 1 deletion hooks/useScrollLock/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"@pansy/use-get-state": "^0.2.5",
"@pansy/use-event-listener": "^0.2.8",
"@pansy/shared": "^1.2.0"
"@pansy/shared": "^1.3.1"
},
"publishConfig": {
"registry": "https://registry.npmjs.org",
Expand Down
1 change: 1 addition & 0 deletions hooks/useSessionStorageState/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0"
},
"publishConfig": {
Expand Down
3 changes: 2 additions & 1 deletion hooks/useSessionStorageState/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { isBrowser, createUseStorageState } from '@pansy/hook-utils';
import { createUseStorageState } from '@pansy/hook-utils';
import { isBrowser } from '@pansy/shared';

/**
* 将状态存储在 sessionStorage 中的 Hook
Expand Down
2 changes: 1 addition & 1 deletion hooks/useSize/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"dependencies": {
"@juggle/resize-observer": "^3.3.1",
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-raf-state": "0.2.5"
},
Expand Down
1 change: 1 addition & 0 deletions hooks/useTitle/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-unmount": "0.2.5"
},
Expand Down
2 changes: 1 addition & 1 deletion hooks/useTitle/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useRef } from 'react';
import { useUnmount } from '@pansy/use-unmount';
import { isBrowser } from '@pansy/hook-utils';
import { isBrowser } from '@pansy/shared';

export interface Options {
/** 组件卸载时,是否恢复上一个页面标题 */
Expand Down
2 changes: 1 addition & 1 deletion hooks/useWatermark/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/hook-utils": "0.3.0",
"@pansy/use-memoized-fn": "0.2.5",
"@pansy/use-unmount": "0.2.5",
Expand Down
2 changes: 1 addition & 1 deletion hooks/utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
},
"dependencies": {
"@pansy/shared": "^1.2.0",
"@pansy/shared": "^1.3.1",
"@pansy/use-memoized-fn": "0.2.5",
"@pansy/use-unmount": "0.2.5",
"@pansy/use-update-effect": "0.2.4",
Expand Down
3 changes: 0 additions & 3 deletions hooks/utils/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
export { createUpdateEffect } from '@pansy/use-update-effect';
export { createUseStorageState } from './utils/createUseStorageState';
export { depsAreSame } from './utils/depsAreSame';
export { isBrowser } from './utils/isBrowser';
export {
createEffectWithTarget,
useEffectWithTarget,
useLayoutEffectWithTarget
} from './utils/useEffectWithTarget';
export { canUseDom } from './utils/canUseDom';
export { useIsomorphicLayoutEffectWithTarget } from './utils/useIsomorphicLayoutEffectWithTarget';
export { useDeepCompareEffectWithTarget } from './utils/useDeepCompareWithTarget';

Expand Down
3 changes: 0 additions & 3 deletions hooks/utils/src/utils/canUseDom.ts

This file was deleted.

17 changes: 0 additions & 17 deletions hooks/utils/src/utils/depsAreSame.ts

This file was deleted.

6 changes: 0 additions & 6 deletions hooks/utils/src/utils/isBrowser.ts

This file was deleted.

3 changes: 1 addition & 2 deletions hooks/utils/src/utils/useEffectWithTarget.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useEffect, useLayoutEffect, useRef } from 'react';
import { useUnmount } from '@pansy/use-unmount';
import { depsAreSame } from './depsAreSame';
import { getTargetElement } from '@pansy/shared/react';
import { getTargetElement, depsAreSame } from '@pansy/shared/react';

import type { DependencyList, EffectCallback } from 'react';
import type { BasicTarget } from '@pansy/shared/react';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isBrowser } from './isBrowser';
import { isBrowser } from '@pansy/shared';
import { useEffectWithTarget, useLayoutEffectWithTarget } from './useEffectWithTarget';

export const useIsomorphicLayoutEffectWithTarget = isBrowser
Expand Down
Loading

0 comments on commit 3989c35

Please sign in to comment.