@8ms/helpers 2.4.12 → 2.4.13

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.
@@ -2,22 +2,21 @@ 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
- const useAsyncEffect = (effect, destroy, inputs) => {
6
- const hasDestroy = typeof destroy === "function";
7
- (0, react.useEffect)(function() {
5
+ const useAsyncEffect = (effect, destroyOrInputs, inputs) => {
6
+ const hasDestroy = "function" === typeof destroyOrInputs;
7
+ const destroy = hasDestroy ? destroyOrInputs : void 0;
8
+ (0, react.useEffect)(() => {
8
9
  let result;
9
10
  let mounted = true;
10
- let maybePromise = effect(function() {
11
- return mounted;
12
- });
13
- Promise.resolve(maybePromise).then(function(value) {
11
+ const maybePromise = effect(() => mounted);
12
+ Promise.resolve(maybePromise).then((value) => {
14
13
  result = value;
15
14
  });
16
- return function() {
15
+ return () => {
17
16
  mounted = false;
18
- if (hasDestroy) destroy(result);
17
+ if (hasDestroy && destroy) destroy(result);
19
18
  };
20
- }, hasDestroy ? inputs : destroy);
19
+ }, hasDestroy ? inputs : destroyOrInputs);
21
20
  };
22
21
  //#endregion
23
22
  exports.useAsyncEffect = useAsyncEffect;
@@ -1,4 +1,8 @@
1
1
  //#region src/nextJs/client/useAsyncEffect.d.ts
2
- declare const useAsyncEffect: <T>(effect: (isMounted: () => boolean) => T | Promise<T>, destroy?: (result?: T) => void, inputs?: any[]) => void;
2
+ type UseAsyncEffect = {
3
+ (effect: (isMounted: () => boolean) => unknown | Promise<unknown>, inputs?: any[]): void;
4
+ <T>(effect: (isMounted: () => boolean) => T | Promise<T>, destroy?: (result?: T) => void, inputs?: any[]): void;
5
+ };
6
+ declare const useAsyncEffect: UseAsyncEffect;
3
7
  //#endregion
4
8
  export { useAsyncEffect };
@@ -1,4 +1,8 @@
1
1
  //#region src/nextJs/client/useAsyncEffect.d.ts
2
- declare const useAsyncEffect: <T>(effect: (isMounted: () => boolean) => T | Promise<T>, destroy?: (result?: T) => void, inputs?: any[]) => void;
2
+ type UseAsyncEffect = {
3
+ (effect: (isMounted: () => boolean) => unknown | Promise<unknown>, inputs?: any[]): void;
4
+ <T>(effect: (isMounted: () => boolean) => T | Promise<T>, destroy?: (result?: T) => void, inputs?: any[]): void;
5
+ };
6
+ declare const useAsyncEffect: UseAsyncEffect;
3
7
  //#endregion
4
8
  export { useAsyncEffect };
@@ -1,21 +1,20 @@
1
1
  import { useEffect } from "react";
2
2
  //#region src/nextJs/client/useAsyncEffect.ts
3
- const useAsyncEffect = (effect, destroy, inputs) => {
4
- const hasDestroy = typeof destroy === "function";
5
- useEffect(function() {
3
+ const useAsyncEffect = (effect, destroyOrInputs, inputs) => {
4
+ const hasDestroy = "function" === typeof destroyOrInputs;
5
+ const destroy = hasDestroy ? destroyOrInputs : void 0;
6
+ useEffect(() => {
6
7
  let result;
7
8
  let mounted = true;
8
- let maybePromise = effect(function() {
9
- return mounted;
10
- });
11
- Promise.resolve(maybePromise).then(function(value) {
9
+ const maybePromise = effect(() => mounted);
10
+ Promise.resolve(maybePromise).then((value) => {
12
11
  result = value;
13
12
  });
14
- return function() {
13
+ return () => {
15
14
  mounted = false;
16
- if (hasDestroy) destroy(result);
15
+ if (hasDestroy && destroy) destroy(result);
17
16
  };
18
- }, hasDestroy ? inputs : destroy);
17
+ }, hasDestroy ? inputs : destroyOrInputs);
19
18
  };
20
19
  //#endregion
21
20
  export { useAsyncEffect };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@8ms/helpers",
3
3
  "license": "UNLICENSED",
4
- "version": "2.4.12",
4
+ "version": "2.4.13",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/8millionstories-organisation/8ms-helpers-ts.git"