@pawover/kit 0.0.0-alpha.4 → 0.0.0-alpha.5
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/dist/hooks/react/useCreation.js +9 -1
- package/dist/hooks/react/useLatest.js +7 -0
- package/dist/hooks/react/useUnmount.js +1 -0
- package/dist/hooks/react.js +1 -0
- package/dist/types/hooks/react/useCreation.d.ts +8 -0
- package/dist/types/hooks/react/useLatest.d.ts +7 -0
- package/dist/types/hooks/react/useUnmount.d.ts +1 -0
- package/dist/types/hooks/react.d.ts +1 -0
- package/dist/types/utils/typeof.d.ts +8 -0
- package/dist/utils/typeof.js +35 -0
- package/package.json +1 -3
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
import { isEqual } from "radashi";
|
|
2
1
|
import { useRef } from "react";
|
|
2
|
+
import { isEqual } from "src/utils";
|
|
3
|
+
/**
|
|
4
|
+
* useCreation
|
|
5
|
+
* @reference https://ahooks.js.org/zh-CN/hooks/use-creation
|
|
6
|
+
*
|
|
7
|
+
* @template T
|
|
8
|
+
* @param {() => T} factory
|
|
9
|
+
* @param {DependencyList} deps
|
|
10
|
+
*/
|
|
3
11
|
export function useCreation(factory, deps) {
|
|
4
12
|
const { current } = useRef({ deps, result: undefined, isInitialized: false });
|
|
5
13
|
if (current.isInitialized === false || !isEqual(current.deps, deps)) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./react/index";
|
|
@@ -1,2 +1,10 @@
|
|
|
1
1
|
import { type DependencyList } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* useCreation
|
|
4
|
+
* @reference https://ahooks.js.org/zh-CN/hooks/use-creation
|
|
5
|
+
*
|
|
6
|
+
* @template T
|
|
7
|
+
* @param {() => T} factory
|
|
8
|
+
* @param {DependencyList} deps
|
|
9
|
+
*/
|
|
2
10
|
export declare function useCreation<T>(factory: () => T, deps: DependencyList): T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./react/index";
|
|
@@ -27,3 +27,11 @@ export declare function isURLSearchParams<T extends Window>(value: unknown): val
|
|
|
27
27
|
export declare function isClass<T extends Class<AnyObject>>(value: unknown): value is T;
|
|
28
28
|
export declare function isInteger<T extends number>(value: unknown): value is T;
|
|
29
29
|
export declare function isIterable<T extends Iterable<unknown>>(value: unknown): value is T;
|
|
30
|
+
/**
|
|
31
|
+
* 判断给定的值是否相等
|
|
32
|
+
* @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
|
|
33
|
+
*
|
|
34
|
+
* @param {T} x
|
|
35
|
+
* @param {T} y
|
|
36
|
+
*/
|
|
37
|
+
export declare function isEqual<T>(x: T, y: T): boolean;
|
package/dist/utils/typeof.js
CHANGED
|
@@ -112,3 +112,38 @@ export function isInteger(value) {
|
|
|
112
112
|
export function isIterable(value) {
|
|
113
113
|
return isObject(value) && Symbol.iterator in value;
|
|
114
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* 判断给定的值是否相等
|
|
117
|
+
* @reference https://github.com/radashi-org/radashi/blob/main/src/typed/isEqual.ts
|
|
118
|
+
*
|
|
119
|
+
* @param {T} x
|
|
120
|
+
* @param {T} y
|
|
121
|
+
*/
|
|
122
|
+
export function isEqual(x, y) {
|
|
123
|
+
if (Object.is(x, y)) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
if (x instanceof Date && y instanceof Date) {
|
|
127
|
+
return x.getTime() === y.getTime();
|
|
128
|
+
}
|
|
129
|
+
if (x instanceof RegExp && y instanceof RegExp) {
|
|
130
|
+
return x.toString() === y.toString();
|
|
131
|
+
}
|
|
132
|
+
if (typeof x !== "object" || x === null || typeof y !== "object" || y === null) {
|
|
133
|
+
return false;
|
|
134
|
+
}
|
|
135
|
+
const keysX = Reflect.ownKeys(x);
|
|
136
|
+
const keysY = Reflect.ownKeys(y);
|
|
137
|
+
if (keysX.length !== keysY.length) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
for (const key of keysX) {
|
|
141
|
+
if (!Reflect.has(y, key)) {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
if (!isEqual(x[key], y[key])) {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return true;
|
|
149
|
+
}
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"description": "pawover's kit",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"version": "0.0.0-alpha.
|
|
7
|
+
"version": "0.0.0-alpha.5",
|
|
8
8
|
"packageManager": "pnpm@10.20.0",
|
|
9
9
|
"engines": {
|
|
10
10
|
"node": ">=22.20.0"
|
|
@@ -61,7 +61,6 @@
|
|
|
61
61
|
"eslint-plugin-antfu": "^3.1.1",
|
|
62
62
|
"globals": "^16.5.0",
|
|
63
63
|
"prettier": "^3.6.2",
|
|
64
|
-
"radashi": "^12.7.0",
|
|
65
64
|
"react": "^19.2.0",
|
|
66
65
|
"rimraf": "^6.1.0",
|
|
67
66
|
"taze": "^19.9.0",
|
|
@@ -72,7 +71,6 @@
|
|
|
72
71
|
},
|
|
73
72
|
"peerDependencies": {
|
|
74
73
|
"ahooks": ">=3.9.6",
|
|
75
|
-
"radashi": ">=12.7.0",
|
|
76
74
|
"react": ">=19.2.0",
|
|
77
75
|
"vue": ">=3.5.24"
|
|
78
76
|
},
|