@8ms/helpers 2.4.13 → 2.4.14
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/drizzle/server/DrizzleNamespace.d.cts +0 -1
- package/dist/drizzle/server/DrizzleNamespace.d.mts +1 -0
- package/dist/nextJs/client/useAsyncEffect.cjs +14 -10
- package/dist/nextJs/client/useAsyncEffect.d.cts +2 -5
- package/dist/nextJs/client/useAsyncEffect.d.mts +2 -5
- package/dist/nextJs/client/useAsyncEffect.mjs +14 -10
- package/package.json +1 -1
|
@@ -2,21 +2,25 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
2
2
|
require("../../_virtual/_rolldown/runtime.cjs");
|
|
3
3
|
let react = require("react");
|
|
4
4
|
//#region src/nextJs/client/useAsyncEffect.ts
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Based on https://github.com/rauldeheer/use-async-effect/tree/master
|
|
7
|
+
*/
|
|
8
|
+
function useAsyncEffect(effect, destroy, inputs) {
|
|
9
|
+
const hasDestroy = typeof destroy === "function";
|
|
10
|
+
(0, react.useEffect)(function() {
|
|
9
11
|
let result;
|
|
10
12
|
let mounted = true;
|
|
11
|
-
|
|
12
|
-
|
|
13
|
+
let maybePromise = effect(function() {
|
|
14
|
+
return mounted;
|
|
15
|
+
});
|
|
16
|
+
Promise.resolve(maybePromise).then(function(value) {
|
|
13
17
|
result = value;
|
|
14
18
|
});
|
|
15
|
-
return ()
|
|
19
|
+
return function() {
|
|
16
20
|
mounted = false;
|
|
17
|
-
if (hasDestroy
|
|
21
|
+
if (hasDestroy) destroy(result);
|
|
18
22
|
};
|
|
19
|
-
}, hasDestroy ? inputs :
|
|
20
|
-
}
|
|
23
|
+
}, hasDestroy ? inputs : destroy);
|
|
24
|
+
}
|
|
21
25
|
//#endregion
|
|
22
26
|
exports.useAsyncEffect = useAsyncEffect;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
//#region src/nextJs/client/useAsyncEffect.d.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
<T>(effect: (isMounted: () => boolean) => T | Promise<T>, destroy?: (result?: T) => void, inputs?: any[]): void;
|
|
5
|
-
};
|
|
6
|
-
declare const useAsyncEffect: UseAsyncEffect;
|
|
2
|
+
declare function useAsyncEffect(effect: (isMounted: () => boolean) => unknown | Promise<unknown>, inputs?: any[]): void;
|
|
3
|
+
declare function useAsyncEffect<V>(effect: (isMounted: () => boolean) => V | Promise<V>, destroy?: (result?: V) => void, inputs?: any[]): void;
|
|
7
4
|
//#endregion
|
|
8
5
|
export { useAsyncEffect };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
//#region src/nextJs/client/useAsyncEffect.d.ts
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
<T>(effect: (isMounted: () => boolean) => T | Promise<T>, destroy?: (result?: T) => void, inputs?: any[]): void;
|
|
5
|
-
};
|
|
6
|
-
declare const useAsyncEffect: UseAsyncEffect;
|
|
2
|
+
declare function useAsyncEffect(effect: (isMounted: () => boolean) => unknown | Promise<unknown>, inputs?: any[]): void;
|
|
3
|
+
declare function useAsyncEffect<V>(effect: (isMounted: () => boolean) => V | Promise<V>, destroy?: (result?: V) => void, inputs?: any[]): void;
|
|
7
4
|
//#endregion
|
|
8
5
|
export { useAsyncEffect };
|
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { useEffect } from "react";
|
|
2
2
|
//#region src/nextJs/client/useAsyncEffect.ts
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Based on https://github.com/rauldeheer/use-async-effect/tree/master
|
|
5
|
+
*/
|
|
6
|
+
function useAsyncEffect(effect, destroy, inputs) {
|
|
7
|
+
const hasDestroy = typeof destroy === "function";
|
|
8
|
+
useEffect(function() {
|
|
7
9
|
let result;
|
|
8
10
|
let mounted = true;
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
let maybePromise = effect(function() {
|
|
12
|
+
return mounted;
|
|
13
|
+
});
|
|
14
|
+
Promise.resolve(maybePromise).then(function(value) {
|
|
11
15
|
result = value;
|
|
12
16
|
});
|
|
13
|
-
return ()
|
|
17
|
+
return function() {
|
|
14
18
|
mounted = false;
|
|
15
|
-
if (hasDestroy
|
|
19
|
+
if (hasDestroy) destroy(result);
|
|
16
20
|
};
|
|
17
|
-
}, hasDestroy ? inputs :
|
|
18
|
-
}
|
|
21
|
+
}, hasDestroy ? inputs : destroy);
|
|
22
|
+
}
|
|
19
23
|
//#endregion
|
|
20
24
|
export { useAsyncEffect };
|