@jelper/hooks 0.2.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -31
- package/es/index.js +25 -1779
- package/es/useAsync.js +73 -0
- package/es/useBoolState.js +23 -0
- package/es/useCreate.js +11 -0
- package/es/useDebounce.js +18 -0
- package/es/useIgnoreAbortErrCb.js +16 -0
- package/es/useInterval.js +29 -0
- package/es/useIsMounted.js +18 -0
- package/es/useIsUnmounted.js +17 -0
- package/es/useMount.js +11 -0
- package/es/useOption.js +19 -0
- package/es/useResizeObserver.js +50 -0
- package/es/useRtCb.js +15 -0
- package/es/useRtRef.js +13 -0
- package/es/useSafeRunner.js +20 -0
- package/es/useThrottle.js +18 -0
- package/es/useTimeout.js +29 -0
- package/es/useUnmount.js +17 -0
- package/es/useUpdateEff.js +17 -0
- package/es/useValue.js +29 -0
- package/lib/index.js +48 -1773
- package/lib/useAsync.js +90 -0
- package/lib/useBoolState.js +25 -0
- package/lib/useCreate.js +13 -0
- package/lib/useDebounce.js +27 -0
- package/lib/useIgnoreAbortErrCb.js +19 -0
- package/lib/useInterval.js +35 -0
- package/lib/useIsMounted.js +20 -0
- package/lib/useIsUnmounted.js +19 -0
- package/lib/useMount.js +13 -0
- package/lib/useOption.js +33 -0
- package/lib/useResizeObserver.js +53 -0
- package/lib/useRtCb.js +25 -0
- package/lib/useRtRef.js +15 -0
- package/lib/useSafeRunner.js +25 -0
- package/lib/useThrottle.js +27 -0
- package/lib/useTimeout.js +35 -0
- package/lib/useUnmount.js +22 -0
- package/lib/useUpdateEff.js +19 -0
- package/lib/useValue.js +34 -0
- package/package.json +13 -5
- package/types/index.d.ts +8 -10
- package/types/useAsync.d.ts +22 -8
- package/types/useBoolState.d.ts +7 -1
- package/types/useCreate.d.ts +7 -1
- package/types/useDebounce.d.ts +6 -0
- package/types/useIgnoreAbortErrCb.d.ts +12 -0
- package/types/useInterval.d.ts +4 -1
- package/types/useIsMounted.d.ts +8 -0
- package/types/useIsUnmounted.d.ts +8 -0
- package/types/useMount.d.ts +7 -1
- package/types/useOption.d.ts +15 -0
- package/types/useRtCb.d.ts +8 -1
- package/types/useRtRef.d.ts +8 -1
- package/types/useSafeRunner.d.ts +8 -0
- package/types/useThrottle.d.ts +5 -6
- package/types/useTimeout.d.ts +8 -5
- package/types/useUnmount.d.ts +7 -1
- package/types/useUpdateEff.d.ts +8 -0
- package/types/useValue.d.ts +8 -0
- package/types/useIsUnmount.d.ts +0 -2
- package/types/useListener.d.ts +0 -2
- package/types/useParamsState.d.ts +0 -6
- package/types/useRtEffect.d.ts +0 -2
- package/types/useRtState.d.ts +0 -6
- package/types/useSafeCb.d.ts +0 -2
- package/types/useSafeState.d.ts +0 -3
- package/types/useUpdateEffect.d.ts +0 -1
package/types/useAsync.d.ts
CHANGED
|
@@ -1,13 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-18 23:44:38
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-19 22:53:22
|
|
6
|
+
*/
|
|
7
|
+
type Parameter<T extends (p: any) => any> = Parameters<T>[0];
|
|
8
|
+
interface Opt<T extends (p: any) => any, R> {
|
|
9
|
+
defParam?: Parameter<T>;
|
|
3
10
|
immediate?: boolean;
|
|
4
11
|
format?: (p: ReturnType<T>) => R;
|
|
5
12
|
catchParam?: boolean;
|
|
13
|
+
onAbort?: (this: AbortSignal, ev: Event) => any;
|
|
6
14
|
}
|
|
7
|
-
declare const useAsync: <T extends (
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
declare const useAsync: <T extends (p: any, opt?: {
|
|
16
|
+
signal: AbortController['signal'];
|
|
17
|
+
}) => Promise<any>, R = any>(asyncFn: T, opt?: Opt<T, R>) => [
|
|
18
|
+
R | undefined,
|
|
19
|
+
{
|
|
20
|
+
run: (runParam?: Partial<Parameter<T>>) => Promise<void>;
|
|
21
|
+
refresh: () => Promise<void>;
|
|
22
|
+
loading: boolean;
|
|
23
|
+
error?: Error;
|
|
24
|
+
param: Partial<Parameter<T>>;
|
|
25
|
+
}
|
|
26
|
+
];
|
|
13
27
|
export default useAsync;
|
package/types/useBoolState.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-16 11:16:34
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-16 11:21:54
|
|
6
|
+
*/
|
|
7
|
+
declare const useBoolState: (value: boolean) => (boolean | ((switchValue?: React.SetStateAction<boolean>) => void))[];
|
|
2
8
|
export default useBoolState;
|
package/types/useCreate.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-16 11:34:59
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-19 22:53:33
|
|
6
|
+
*/
|
|
7
|
+
declare const useCreate: (cb: () => void) => void;
|
|
2
8
|
export default useCreate;
|
package/types/useDebounce.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-19 22:55:14
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-19 22:55:14
|
|
6
|
+
*/
|
|
1
7
|
import { DebounceSettings, DebouncedFunc } from 'lodash-es';
|
|
2
8
|
declare const useDebounce: <T extends (...args: any) => any>(cb: T, wait?: number, opts?: DebounceSettings) => DebouncedFunc<T>;
|
|
3
9
|
export default useDebounce;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-19 22:28:14
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-19 22:57:23
|
|
6
|
+
*/
|
|
7
|
+
/// <reference types="react" />
|
|
8
|
+
interface Opts<T> {
|
|
9
|
+
onAbort: (err: Error) => T;
|
|
10
|
+
}
|
|
11
|
+
declare const useIgnoreAbortErrCb: <T = any>(cb: (err: Error) => T, deps?: import("react").DependencyList, opts?: Opts<T>) => (err: Error) => T | undefined;
|
|
12
|
+
export default useIgnoreAbortErrCb;
|
package/types/useInterval.d.ts
CHANGED
package/types/useMount.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-18 00:21:16
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-18 00:21:16
|
|
6
|
+
*/
|
|
7
|
+
declare const useMount: (cb: () => void) => void;
|
|
2
8
|
export default useMount;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-16 11:35:37
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-16 21:31:54
|
|
6
|
+
*/
|
|
7
|
+
declare const useOption: <T extends {}>(defOpt?: Partial<T>) => [
|
|
8
|
+
Partial<T>,
|
|
9
|
+
{
|
|
10
|
+
reset: () => void;
|
|
11
|
+
setOption: React.Dispatch<React.SetStateAction<Partial<T>>>;
|
|
12
|
+
update: React.Dispatch<React.SetStateAction<Partial<T>>>;
|
|
13
|
+
}
|
|
14
|
+
];
|
|
15
|
+
export default useOption;
|
package/types/useRtCb.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-17 00:22:11
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-17 00:22:56
|
|
6
|
+
*/
|
|
7
|
+
import { DependencyList } from 'react';
|
|
8
|
+
declare const useRtCb: <T extends Function>(cb: T, deps?: DependencyList) => T;
|
|
2
9
|
export default useRtCb;
|
package/types/useRtRef.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-16 22:19:57
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-17 00:10:45
|
|
6
|
+
*/
|
|
1
7
|
/// <reference types="react" />
|
|
2
|
-
|
|
8
|
+
declare const useRtRef: <T>(val: T) => import("react").MutableRefObject<T>;
|
|
9
|
+
export default useRtRef;
|
package/types/useThrottle.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { ThrottleSettings } from 'lodash-es';
|
|
2
1
|
/**
|
|
3
|
-
*
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
6
|
-
* @
|
|
7
|
-
* @returns 节流函数
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-19 22:55:28
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-19 22:55:48
|
|
8
6
|
*/
|
|
7
|
+
import { ThrottleSettings } from 'lodash-es';
|
|
9
8
|
declare const useThrottle: <T extends (...args: any) => any>(cb: T, wait?: number, opts?: ThrottleSettings) => import("lodash-es").DebouncedFunc<(...arg: Parameters<T>) => void>;
|
|
10
9
|
export default useThrottle;
|
package/types/useTimeout.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* @
|
|
4
|
-
* @
|
|
5
|
-
* @
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-19 23:10:13
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-19 23:10:13
|
|
6
6
|
*/
|
|
7
|
-
declare const useTimeout: (
|
|
7
|
+
declare const useTimeout: () => [
|
|
8
|
+
(callback: Function, timeout?: number, ...arg: any[]) => void,
|
|
9
|
+
() => void
|
|
10
|
+
];
|
|
8
11
|
export default useTimeout;
|
package/types/useUnmount.d.ts
CHANGED
|
@@ -1,2 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-16 11:35:20
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-18 00:17:09
|
|
6
|
+
*/
|
|
7
|
+
declare const useUnmount: (cb: () => void) => void;
|
|
2
8
|
export default useUnmount;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @Author: apathyjade
|
|
3
|
+
* @Date: 2025-03-16 11:35:13
|
|
4
|
+
* @Last Modified by: apathyjade
|
|
5
|
+
* @Last Modified time: 2025-03-16 11:35:13
|
|
6
|
+
*/
|
|
7
|
+
declare const useUpdateEffect: (cb: React.EffectCallback, deps?: React.DependencyList) => void;
|
|
8
|
+
export default useUpdateEffect;
|
package/types/useIsUnmount.d.ts
DELETED
package/types/useListener.d.ts
DELETED
package/types/useRtEffect.d.ts
DELETED
package/types/useRtState.d.ts
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
interface Options<T> {
|
|
3
|
-
isEqual?: (a: T, b: T) => boolean;
|
|
4
|
-
}
|
|
5
|
-
export default function useRtState<T = any>(value: T, onChange?: (value: T) => void, opts?: Options<T>): (T | import("react").Dispatch<import("react").SetStateAction<T>>)[];
|
|
6
|
-
export {};
|
package/types/useSafeCb.d.ts
DELETED
package/types/useSafeState.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export default function useUpdateEffect(cb: () => void, deps: any[]): void;
|