@tamagui/use-async 2.0.0-rc.4 → 2.0.0-rc.40

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.
Files changed (52) hide show
  1. package/dist/cjs/errors.cjs +14 -11
  2. package/dist/cjs/errors.native.js +71 -43
  3. package/dist/cjs/errors.native.js.map +1 -1
  4. package/dist/cjs/idle.cjs +52 -30
  5. package/dist/cjs/idle.native.js +55 -38
  6. package/dist/cjs/idle.native.js.map +1 -1
  7. package/dist/cjs/index.cjs +7 -5
  8. package/dist/cjs/index.native.js +7 -5
  9. package/dist/cjs/index.native.js.map +1 -1
  10. package/dist/cjs/sleep.cjs +16 -11
  11. package/dist/cjs/sleep.native.js +21 -16
  12. package/dist/cjs/sleep.native.js.map +1 -1
  13. package/dist/cjs/useAsyncEffect.cjs +28 -18
  14. package/dist/cjs/useAsyncEffect.native.js +34 -20
  15. package/dist/cjs/useAsyncEffect.native.js.map +1 -1
  16. package/dist/esm/errors.mjs +2 -1
  17. package/dist/esm/errors.mjs.map +1 -1
  18. package/dist/esm/errors.native.js +59 -33
  19. package/dist/esm/errors.native.js.map +1 -1
  20. package/dist/esm/idle.mjs +38 -18
  21. package/dist/esm/idle.mjs.map +1 -1
  22. package/dist/esm/idle.native.js +41 -26
  23. package/dist/esm/idle.native.js.map +1 -1
  24. package/dist/esm/index.js +4 -4
  25. package/dist/esm/index.js.map +1 -6
  26. package/dist/esm/sleep.mjs +4 -1
  27. package/dist/esm/sleep.mjs.map +1 -1
  28. package/dist/esm/sleep.native.js +5 -2
  29. package/dist/esm/sleep.native.js.map +1 -1
  30. package/dist/esm/useAsyncEffect.mjs +14 -6
  31. package/dist/esm/useAsyncEffect.mjs.map +1 -1
  32. package/dist/esm/useAsyncEffect.native.js +20 -8
  33. package/dist/esm/useAsyncEffect.native.js.map +1 -1
  34. package/package.json +5 -8
  35. package/dist/cjs/errors.js +0 -25
  36. package/dist/cjs/errors.js.map +0 -6
  37. package/dist/cjs/idle.js +0 -36
  38. package/dist/cjs/idle.js.map +0 -6
  39. package/dist/cjs/index.js +0 -18
  40. package/dist/cjs/index.js.map +0 -6
  41. package/dist/cjs/sleep.js +0 -25
  42. package/dist/cjs/sleep.js.map +0 -6
  43. package/dist/cjs/useAsyncEffect.js +0 -56
  44. package/dist/cjs/useAsyncEffect.js.map +0 -6
  45. package/dist/esm/errors.js +0 -9
  46. package/dist/esm/errors.js.map +0 -6
  47. package/dist/esm/idle.js +0 -21
  48. package/dist/esm/idle.js.map +0 -6
  49. package/dist/esm/sleep.js +0 -9
  50. package/dist/esm/sleep.js.map +0 -6
  51. package/dist/esm/useAsyncEffect.js +0 -41
  52. package/dist/esm/useAsyncEffect.js.map +0 -6
@@ -3,20 +3,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
5
  var __export = (target, all) => {
6
- for (var name in all) __defProp(target, name, {
7
- get: all[name],
8
- enumerable: !0
9
- });
10
- },
11
- __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
13
14
  get: () => from[key],
14
15
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
15
16
  });
16
- return to;
17
- };
17
+ }
18
+ return to;
19
+ };
18
20
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
19
- value: !0
21
+ value: true
20
22
  }), mod);
21
23
  var useAsyncEffect_exports = {};
22
24
  __export(useAsyncEffect_exports, {
@@ -25,8 +27,8 @@ __export(useAsyncEffect_exports, {
25
27
  useAsyncLayoutEffect: () => useAsyncLayoutEffect
26
28
  });
27
29
  module.exports = __toCommonJS(useAsyncEffect_exports);
28
- var import_react = require("react"),
29
- import_errors = require("./errors.cjs");
30
+ var import_react = require("react");
31
+ var import_errors = require("./errors.cjs");
30
32
  const DEBUG_LEVEL = 0;
31
33
  function useAsyncEffect(cb, deps = []) {
32
34
  useAsyncEffectOfType(import_react.useEffect, cb, deps);
@@ -36,12 +38,12 @@ function useAsyncLayoutEffect(cb, deps = []) {
36
38
  }
37
39
  function useAsyncEffectOfType(type, cb, deps = []) {
38
40
  type(() => {
39
- const controller = new AbortController(),
40
- signal = controller.signal;
41
+ const controller = new AbortController();
42
+ const signal = controller.signal;
41
43
  try {
42
44
  const value = cb(signal, ...deps);
43
45
  Promise.resolve(value).then(async res => {
44
- if (res && typeof res == "function") {
46
+ if (res && typeof res === "function") {
45
47
  if (signal.aborted) return res();
46
48
  signal.addEventListener("abort", res);
47
49
  }
@@ -50,12 +52,20 @@ function useAsyncEffectOfType(type, cb, deps = []) {
50
52
  handleError(error);
51
53
  }
52
54
  function handleError(error) {
53
- if (error instanceof import_errors.AbortError) return DEBUG_LEVEL > 2 && console.info(`\u{1F41B} useAsyncEffect aborted: ${error.message}`), null;
54
- if (typeof error == "object" && error.name === "AbortError") return null;
55
+ if (error instanceof import_errors.AbortError) {
56
+ if (DEBUG_LEVEL > 2) {
57
+ console.info(`\u{1F41B} useAsyncEffect aborted: ${error.message}`);
58
+ }
59
+ return null;
60
+ }
61
+ if (typeof error === "object" && error.name === "AbortError") {
62
+ return null;
63
+ }
55
64
  throw error;
56
65
  }
57
66
  return () => {
58
- signal.aborted || controller.abort();
67
+ if (signal.aborted) return;
68
+ controller.abort();
59
69
  };
60
70
  }, deps);
61
71
  }
@@ -5,20 +5,22 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
7
  var __export = (target, all) => {
8
- for (var name in all) __defProp(target, name, {
9
- get: all[name],
10
- enumerable: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: !0
23
+ value: true
22
24
  }), mod);
23
25
  var useAsyncEffect_exports = {};
24
26
  __export(useAsyncEffect_exports, {
@@ -27,15 +29,19 @@ __export(useAsyncEffect_exports, {
27
29
  useAsyncLayoutEffect: () => useAsyncLayoutEffect
28
30
  });
29
31
  module.exports = __toCommonJS(useAsyncEffect_exports);
30
- var import_react = require("react"),
31
- import_errors = require("./errors.native.js");
32
+ var import_react = require("react");
33
+ var import_errors = require("./errors.native.js");
32
34
  function _instanceof(left, right) {
33
- return right != null && typeof Symbol < "u" && right[Symbol.hasInstance] ? !!right[Symbol.hasInstance](left) : left instanceof right;
35
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
36
+ return !!right[Symbol.hasInstance](left);
37
+ } else {
38
+ return left instanceof right;
39
+ }
34
40
  }
35
41
  function _type_of(obj) {
36
42
  "@swc/helpers - typeof";
37
43
 
38
- return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
44
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
39
45
  }
40
46
  var DEBUG_LEVEL = 0;
41
47
  function useAsyncEffect(cb) {
@@ -49,12 +55,12 @@ function useAsyncLayoutEffect(cb) {
49
55
  function useAsyncEffectOfType(type, cb) {
50
56
  var deps = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
51
57
  type(function () {
52
- var controller = new AbortController(),
53
- signal = controller.signal;
58
+ var controller = new AbortController();
59
+ var signal = controller.signal;
54
60
  try {
55
61
  var value = cb(signal, ...deps);
56
62
  Promise.resolve(value).then(async function (res) {
57
- if (res && typeof res == "function") {
63
+ if (res && typeof res === "function") {
58
64
  if (signal.aborted) return res();
59
65
  signal.addEventListener("abort", res);
60
66
  }
@@ -63,12 +69,20 @@ function useAsyncEffectOfType(type, cb) {
63
69
  handleError(error);
64
70
  }
65
71
  function handleError(error) {
66
- if (_instanceof(error, import_errors.AbortError)) return DEBUG_LEVEL > 2 && console.info(`\u{1F41B} useAsyncEffect aborted: ${error.message}`), null;
67
- if ((typeof error > "u" ? "undefined" : _type_of(error)) === "object" && error.name === "AbortError") return null;
72
+ if (_instanceof(error, import_errors.AbortError)) {
73
+ if (DEBUG_LEVEL > 2) {
74
+ console.info(`\u{1F41B} useAsyncEffect aborted: ${error.message}`);
75
+ }
76
+ return null;
77
+ }
78
+ if ((typeof error === "undefined" ? "undefined" : _type_of(error)) === "object" && error.name === "AbortError") {
79
+ return null;
80
+ }
68
81
  throw error;
69
82
  }
70
83
  return function () {
71
- signal.aborted || controller.abort();
84
+ if (signal.aborted) return;
85
+ controller.abort();
72
86
  };
73
87
  }, deps);
74
88
  }
@@ -1 +1 @@
1
- {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useAsyncEffect_exports","__export","useAsyncEffect","useAsyncEffectOfType","useAsyncLayoutEffect","module","exports","import_react","require","import_errors","_instanceof","left","right","Symbol","hasInstance","_type_of","obj","constructor","DEBUG_LEVEL","cb","deps","arguments","length","useEffect","useLayoutEffect","type","controller","AbortController","signal","Promise","resolve","then","res","aborted","addEventListener","catch","handleError","error"],"sources":["../../src/useAsyncEffect.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,sBAAA;AAAAC,QAAA,CAAAD,sBAAA;EAAAE,cAAA,EAAAA,CAAA,KAAAA,cAAA;EAAAC,oBAAA,EAAAA,CAAA,KAAAA,oBAAA;EAAAC,oBAAA,EAAAA,CAAA,KAAAA;AAAA;AAEAC,MAAA,CAAAC,OAAA,GAAAX,YAA2C,CAAAK,sBAC3C,CAA2B;AAE3B,IAAAO,YAAM,GAAAC,OAAc;EAAAC,aAAA,GAAAD,OAAA;AASb,SAASE,YAAAC,IAAe,EAAAC,KAAyB;EACtD,OAAAA,KAAA,YAAqB,OAAAC,MAAA,UAAWD,KAAI,CAAIC,MAAA,CAAAC,WAAA,MAAAF,KAAA,CAAAC,MAAA,CAAAC,WAAA,EAAAH,IAAA,IAAAA,IAAA,YAAAC,KAAA;AAC1C;AAEO,SAASG,SAAAC,GAAA;EACd,uBAAqB;;EACvB,OAAAA,GAAA,WAAAH,MAAA,UAAAG,GAAA,CAAAC,WAAA,KAAAJ,MAAA,qBAAAG,GAAA;AAEO;AAKL,IAAAE,WAAW;AACT,SAAAhB,cAAmBA,CAAAiB,EAAA,EAAI;EAIvB,IAAAC,IAAI,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EACFlB,oBAAc,CAAGI,YAAW,CAAAgB,SAAI,EAAAJ,EAAA,EAAAC,IAAA;AAEhC;AAEI,SAAAhB,oBAAkBA,CAAAe,EAAA,EAAQ;EACxB,IAAAC,IAAA,GAAAC,SAAW,CAAAC,MAAS,QAAOD,SAAI,iBAAAA,SAAA;EAC/BlB,oBAAO,CAAAI,YAAiB,CAAAiB,eAAY,EAAAL,EAAA,EAAAC,IAAA;AAAA;AACtC,SAEDjB,oBAAiBA,CAAAsB,IAAA,EAAAN,EAAA;EAAA,IACtBC,IAAA,GAASC,SAAO,CAAAC,MAAA,QAAAD,SAAA,iBAAAA,SAAA;EACdI,IAAA,aAAY;IACd,IAAAC,UAAA,OAAAC,eAAA;MAAAC,MAAA,GAAAF,UAAA,CAAAE,MAAA;IAEA;MACE,IAAI7B,KAAA,GAAAoB,EAAA,CAAAS,MAAiB,KAAAR,IAAA;MACnBS,OAAA,CAAAC,OAAI,CAAA/B,KAAA,EAAcgC,IAAA,CAChB,gBAAaC,GAAA;QAOjB,IAAIA,GAAA,IAAO,OAAUA,GAAA,cAAY,EAAM;UACrC,IAAAJ,MAAO,CAAAK,OAAA,SAAAD,GAAA;UAMTJ,MAAM,CAAAM,gBAAA,UAAAF,GAAA;QACR;MAEA,GAAAG,KAAO,CAAAC,WAAM;IACX,EAAI,OAAOC,KAAA;MAEbD,WAAA,CAAAC,KAAA;IACF;IACF,SAAAD,YAAAC,KAAA","ignoreList":[]}
1
+ {"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useAsyncEffect_exports","__export","useAsyncEffect","useAsyncEffectOfType","useAsyncLayoutEffect","module","exports","import_react","require","import_errors","_instanceof","left","right","Symbol","hasInstance","_type_of","obj","constructor","DEBUG_LEVEL","cb","deps","arguments","length","useEffect","useLayoutEffect","type","controller","AbortController","signal","Promise","resolve","then","res","aborted","addEventListener","catch","handleError","error","AbortError"],"sources":["../../src/useAsyncEffect.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,sBAAA;AAAAC,QAAA,CAAAD,sBAAA;EAAAE,cAAA,EAAAA,CAAA,KAAAA,cAAA;EAAAC,oBAAA,EAAAA,CAAA,KAAAA,oBAAA;EAAAC,oBAAA,EAAAA,CAAA,KAAAA;AAAA;AAEAC,MAAA,CAAAC,OAAA,GAAAX,YAA2C,CAAAK,sBAAA;AAC3C,IAAAO,YAAA,GAAAC,OAA2B;AAE3B,IAAAC,aAAM,GAAcD,OAAA;AASb,SAASE,YAAAC,IAAe,EAAAC,KAAyB;EACtD,IAAAA,KAAA,YAAqB,OAAAC,MAAA,gBAAe,IAAID,KAAA,CAAAC,MAAA,CAAAC,WAAA;IAC1C,SAAAF,KAAA,CAAAC,MAAA,CAAAC,WAAA,EAAAH,IAAA;EAEO,OAAS;IACd,OAAAA,IAAA,YAAqBC,KAAA;EACvB;AAEO;AAKL,SAAKG,QAAMA,CAAAC,GAAA;EACT,uBAAmB;;EACnB,OAAAA,GAAM,WAASH,MAAA,KAAW,eAAAG,GAAA,CAAAC,WAAA,KAAAJ,MAAA,qBAAAG,GAAA;AAG1B;AACE,IAAAE,WAAM;AAEN,SAAAhB,cAAgBA,CAAAiB,EAAA,EAAK;EAEjB,IAAAC,IAAA,GAAIC,SAAO,CAAAC,MAAO,QAAQD,SAAY,iBAAAA,SAAA;EACpClB,oBAAW,CAAAI,YAAS,CAAAgB,SAAW,EAAAJ,EAAA,EAAAC,IAAA;AAC/B;AAAoC,SACtChB,qBAAAe,EAAA;EAAA,IACFC,IACC,GAAAC,SAAM,CAAAC,MAAW,QAAAD,SAAA,iBAAAA,SAAA;EAAAlB,oBACN,CAAAI,YAAA,CAAAiB,eAAA,EAAAL,EAAA,EAAAC,IAAA;AACd;AAAiB,SACnBjB,qBAAAsB,IAAA,EAAAN,EAAA;EAEA,IAAAC,IAAA,GAASC,SAAA,CAAAC,MAAY,GAAY,KAAAD,SAAA,iBAAAA,SAAA;EAC/BI,IAAA,aAAI;IACF,IAAAC,UAAI,OAAAC,eAAiB;IACnB,IAAAC,MAAA,GAAAF,UAAa,CAAAE,MAAA;IAA6C,IAC5D;MACA,IAAA7B,KAAO,GAAAoB,EAAA,CAAAS,MAAA,KAAAR,IAAA;MACTS,OAAA,CAAAC,OAAA,CAAA/B,KAAA,EAAAgC,IAAA,iBAAAC,GAAA;QAIA,IAAIA,GAAA,IAAO,OAAAA,GAAU,eAAY,EAAM;UACrC,IAAAJ,MAAO,CAAAK,OAAA,SAAAD,GAAA;UACTJ,MAAA,CAAAM,gBAAA,UAAAF,GAAA;QAKA;MACF,GAAAG,KAAA,CAAAC,WAAA;IAEA,SAAOC,KAAM;MACXD,WAAW,CAAAC,KAAA;IACX;IACF,SAAAD,YAAAC,KAAA;MACC,IAAI3B,WAAA,CAAA2B,KAAA,EAAA5B,aAAA,CAAA6B,UAAA;QACT,IAAApB,WAAA","ignoreList":[]}
@@ -1,6 +1,7 @@
1
1
  class AbortError extends Error {
2
2
  constructor(message = "") {
3
- super(message), this.name = "AbortError";
3
+ super(message);
4
+ this.name = "AbortError";
4
5
  }
5
6
  }
6
7
  export { AbortError };
@@ -1 +1 @@
1
- {"version":3,"names":["AbortError","Error","constructor","message","name"],"sources":["../../src/errors.ts"],"sourcesContent":[null],"mappings":"AAAO,MAAMA,UAAA,SAAmBC,KAAA,CAAM;EACpCC,YAAYC,OAAA,GAAU,IAAI;IACxB,MAAMA,OAAO,GACb,KAAKC,IAAA,GAAO;EACd;AACF","ignoreList":[]}
1
+ {"version":3,"names":["AbortError","Error","constructor","message","name"],"sources":["../../src/errors.ts"],"sourcesContent":[null],"mappings":"AAAO,MAAMA,UAAA,SAAmBC,KAAA,CAAM;EACpCC,YAAYC,OAAA,GAAU,IAAI;IACxB,MAAMA,OAAO;IACb,KAAKC,IAAA,GAAO;EACd;AACF","ignoreList":[]}
@@ -1,79 +1,103 @@
1
1
  function _assert_this_initialized(self) {
2
- if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
2
+ if (self === void 0) {
3
+ throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4
+ }
3
5
  return self;
4
6
  }
5
7
  function _call_super(_this, derived, args) {
6
- return derived = _get_prototype_of(derived), _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
8
+ derived = _get_prototype_of(derived);
9
+ return _possible_constructor_return(_this, _is_native_reflect_construct() ? Reflect.construct(derived, args || [], _get_prototype_of(_this).constructor) : derived.apply(_this, args));
7
10
  }
8
11
  function _class_call_check(instance, Constructor) {
9
- if (!(instance instanceof Constructor)) throw new TypeError("Cannot call a class as a function");
12
+ if (!(instance instanceof Constructor)) {
13
+ throw new TypeError("Cannot call a class as a function");
14
+ }
10
15
  }
11
16
  function _construct(Parent, args, Class) {
12
- return _is_native_reflect_construct() ? _construct = Reflect.construct : _construct = function (Parent2, args2, Class2) {
13
- var a = [null];
14
- a.push.apply(a, args2);
15
- var Constructor = Function.bind.apply(Parent2, a),
16
- instance = new Constructor();
17
- return Class2 && _set_prototype_of(instance, Class2.prototype), instance;
18
- }, _construct.apply(null, arguments);
17
+ if (_is_native_reflect_construct()) {
18
+ _construct = Reflect.construct;
19
+ } else {
20
+ _construct = function construct(Parent2, args2, Class2) {
21
+ var a = [null];
22
+ a.push.apply(a, args2);
23
+ var Constructor = Function.bind.apply(Parent2, a);
24
+ var instance = new Constructor();
25
+ if (Class2) _set_prototype_of(instance, Class2.prototype);
26
+ return instance;
27
+ };
28
+ }
29
+ return _construct.apply(null, arguments);
19
30
  }
20
31
  function _get_prototype_of(o) {
21
- return _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function (o2) {
32
+ _get_prototype_of = Object.setPrototypeOf ? Object.getPrototypeOf : function getPrototypeOf(o2) {
22
33
  return o2.__proto__ || Object.getPrototypeOf(o2);
23
- }, _get_prototype_of(o);
34
+ };
35
+ return _get_prototype_of(o);
24
36
  }
25
37
  function _inherits(subClass, superClass) {
26
- if (typeof superClass != "function" && superClass !== null) throw new TypeError("Super expression must either be null or a function");
38
+ if (typeof superClass !== "function" && superClass !== null) {
39
+ throw new TypeError("Super expression must either be null or a function");
40
+ }
27
41
  subClass.prototype = Object.create(superClass && superClass.prototype, {
28
42
  constructor: {
29
43
  value: subClass,
30
- writable: !0,
31
- configurable: !0
44
+ writable: true,
45
+ configurable: true
32
46
  }
33
- }), superClass && _set_prototype_of(subClass, superClass);
47
+ });
48
+ if (superClass) _set_prototype_of(subClass, superClass);
34
49
  }
35
50
  function _is_native_function(fn) {
36
51
  return Function.toString.call(fn).indexOf("[native code]") !== -1;
37
52
  }
38
53
  function _possible_constructor_return(self, call) {
39
- return call && (_type_of(call) === "object" || typeof call == "function") ? call : _assert_this_initialized(self);
54
+ if (call && (_type_of(call) === "object" || typeof call === "function")) {
55
+ return call;
56
+ }
57
+ return _assert_this_initialized(self);
40
58
  }
41
59
  function _set_prototype_of(o, p) {
42
- return _set_prototype_of = Object.setPrototypeOf || function (o2, p2) {
43
- return o2.__proto__ = p2, o2;
44
- }, _set_prototype_of(o, p);
60
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o2, p2) {
61
+ o2.__proto__ = p2;
62
+ return o2;
63
+ };
64
+ return _set_prototype_of(o, p);
45
65
  }
46
66
  function _type_of(obj) {
47
67
  "@swc/helpers - typeof";
48
68
 
49
- return obj && typeof Symbol < "u" && obj.constructor === Symbol ? "symbol" : typeof obj;
69
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
50
70
  }
51
71
  function _wrap_native_super(Class) {
52
- var _cache = typeof Map == "function" ? /* @__PURE__ */new Map() : void 0;
53
- return _wrap_native_super = function (Class2) {
72
+ var _cache = typeof Map === "function" ? /* @__PURE__ */new Map() : void 0;
73
+ _wrap_native_super = function wrapNativeSuper(Class2) {
54
74
  if (Class2 === null || !_is_native_function(Class2)) return Class2;
55
- if (typeof Class2 != "function") throw new TypeError("Super expression must either be null or a function");
56
- if (typeof _cache < "u") {
75
+ if (typeof Class2 !== "function") {
76
+ throw new TypeError("Super expression must either be null or a function");
77
+ }
78
+ if (typeof _cache !== "undefined") {
57
79
  if (_cache.has(Class2)) return _cache.get(Class2);
58
80
  _cache.set(Class2, Wrapper);
59
81
  }
60
82
  function Wrapper() {
61
83
  return _construct(Class2, arguments, _get_prototype_of(this).constructor);
62
84
  }
63
- return Wrapper.prototype = Object.create(Class2.prototype, {
85
+ Wrapper.prototype = Object.create(Class2.prototype, {
64
86
  constructor: {
65
87
  value: Wrapper,
66
- enumerable: !1,
67
- writable: !0,
68
- configurable: !0
88
+ enumerable: false,
89
+ writable: true,
90
+ configurable: true
69
91
  }
70
- }), _set_prototype_of(Wrapper, Class2);
71
- }, _wrap_native_super(Class);
92
+ });
93
+ return _set_prototype_of(Wrapper, Class2);
94
+ };
95
+ return _wrap_native_super(Class);
72
96
  }
73
97
  function _is_native_reflect_construct() {
74
98
  try {
75
99
  var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
76
- } catch {}
100
+ } catch (_) {}
77
101
  return (_is_native_reflect_construct = function () {
78
102
  return !!result;
79
103
  })();
@@ -86,7 +110,9 @@ var AbortError = /* @__PURE__ */function (Error1) {
86
110
  var message = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "";
87
111
  _class_call_check(this, AbortError2);
88
112
  var _this;
89
- return _this = _call_super(this, AbortError2, [message]), _this.name = "AbortError", _this;
113
+ _this = _call_super(this, AbortError2, [message]);
114
+ _this.name = "AbortError";
115
+ return _this;
90
116
  }
91
117
  return AbortError2;
92
118
  }(_wrap_native_super(Error));
@@ -1 +1 @@
1
- {"version":3,"names":["_assert_this_initialized","self","ReferenceError"],"sources":["../../src/errors.ts"],"sourcesContent":[null],"mappings":"AAAO,SAAMA,wBAAyBA,CAAAC,IAAA;EACpC,IAAAA,IAAA,KAAY,QACV,MAAM,IAAAC,cACD,4DAAO;EACd,OAAAD,IAAA;AACF","ignoreList":[]}
1
+ {"version":3,"names":["_assert_this_initialized","self","ReferenceError"],"sources":["../../src/errors.ts"],"sourcesContent":[null],"mappings":"AAAO,SAAMA,wBAAyBA,CAAAC,IAAA;EACpC,IAAAA,IAAA,KAAY;IACV,MAAM,IAAAC,cAAO;EACb;EACF,OAAAD,IAAA;AACF","ignoreList":[]}
package/dist/esm/idle.mjs CHANGED
@@ -1,24 +1,44 @@
1
1
  import { AbortError } from "./errors.mjs";
2
2
  import { sleep } from "./sleep.mjs";
3
- const idleCb = typeof requestIdleCallback > "u" ? cb => setTimeout(cb, 1) : requestIdleCallback,
4
- idleAsync = () => new Promise(res => {
3
+ const idleCb = typeof requestIdleCallback === "undefined" ? cb => setTimeout(cb, 1) : requestIdleCallback;
4
+ const idleAsync = () => {
5
+ return new Promise(res => {
5
6
  idleCb(res);
6
- }),
7
- idle = async (signal, options) => {
8
- const {
9
- max,
10
- min,
11
- fully
12
- } = options || {},
13
- idleFn = fully ? fullyIdle : idleAsync;
14
- if (max && min && min < max ? await Promise.race([Promise.all([idleFn(), sleep(min)]), sleep(max)]) : max ? await Promise.race([idleFn(), sleep(max)]) : min ? await Promise.all([idleFn(), sleep(min)]) : await idleFn(), signal?.aborted) throw new AbortError();
15
- },
16
- fullyIdle = async signal => {
17
- for (;;) {
18
- const startTime = Date.now();
19
- if (await idle(signal), Date.now() - startTime < 15) break;
20
- if (signal?.aborted) throw new AbortError();
7
+ });
8
+ };
9
+ const idle = async (signal, options) => {
10
+ const {
11
+ max,
12
+ min,
13
+ fully
14
+ } = options || {};
15
+ const idleFn = fully ? fullyIdle : idleAsync;
16
+ if (max && min && min < max) {
17
+ await Promise.race([Promise.all([idleFn(), sleep(min)]), sleep(max)]);
18
+ } else if (max) {
19
+ await Promise.race([idleFn(), sleep(max)]);
20
+ } else if (min) {
21
+ await Promise.all([idleFn(), sleep(min)]);
22
+ } else {
23
+ await idleFn();
24
+ }
25
+ if (signal?.aborted) {
26
+ throw new AbortError();
27
+ }
28
+ };
29
+ const fullyIdle = async signal => {
30
+ while (true) {
31
+ const startTime = Date.now();
32
+ await idle(signal);
33
+ const endTime = Date.now();
34
+ const duration = endTime - startTime;
35
+ if (duration < 15) {
36
+ break;
21
37
  }
22
- };
38
+ if (signal?.aborted) {
39
+ throw new AbortError();
40
+ }
41
+ }
42
+ };
23
43
  export { idle };
24
44
  //# sourceMappingURL=idle.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["AbortError","sleep","idleCb","requestIdleCallback","cb","setTimeout","idleAsync","Promise","res","idle","signal","options","max","min","fully","idleFn","fullyIdle","race","all","aborted","startTime","Date","now"],"sources":["../../src/idle.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAC3B,SAASC,KAAA,QAAa;AAStB,MAAMC,MAAA,GACJ,OAAOC,mBAAA,GAAwB,MAC1BC,EAAA,IAAmBC,UAAA,CAAWD,EAAA,EAAI,CAAC,IACpCD,mBAAA;EAEAG,SAAA,GAAYA,CAAA,KACT,IAAIC,OAAA,CAASC,GAAA,IAAQ;IAC1BN,MAAA,CAAOM,GAAG;EACZ,CAAC;EAGUC,IAAA,GAAO,MAAAA,CAClBC,MAAA,EACAC,OAAA,KAKkB;IAClB,MAAM;QAAEC,GAAA;QAAKC,GAAA;QAAKC;MAAM,IAAIH,OAAA,IAAW,CAAC;MAElCI,MAAA,GAASD,KAAA,GAAQE,SAAA,GAAYV,SAAA;IAYnC,IAVIM,GAAA,IAAOC,GAAA,IAAOA,GAAA,GAAMD,GAAA,GACtB,MAAML,OAAA,CAAQU,IAAA,CAAK,CAACV,OAAA,CAAQW,GAAA,CAAI,CAACH,MAAA,CAAO,GAAGd,KAAA,CAAMY,GAAG,CAAC,CAAC,GAAGZ,KAAA,CAAMW,GAAG,CAAC,CAAC,IAC3DA,GAAA,GACT,MAAML,OAAA,CAAQU,IAAA,CAAK,CAACF,MAAA,CAAO,GAAGd,KAAA,CAAMW,GAAG,CAAC,CAAC,IAChCC,GAAA,GACT,MAAMN,OAAA,CAAQW,GAAA,CAAI,CAACH,MAAA,CAAO,GAAGd,KAAA,CAAMY,GAAG,CAAC,CAAC,IAExC,MAAME,MAAA,CAAO,GAGXL,MAAA,EAAQS,OAAA,EACV,MAAM,IAAInB,UAAA,CAAW;EAEzB;EAEMgB,SAAA,GAAY,MAAON,MAAA,IAAwC;IAC/D,SAAa;MACX,MAAMU,SAAA,GAAYC,IAAA,CAAKC,GAAA,CAAI;MAM3B,IALA,MAAMb,IAAA,CAAKC,MAAM,GACDW,IAAA,CAAKC,GAAA,CAAI,IACEF,SAAA,GAGZ,IACb;MAIF,IAAIV,MAAA,EAAQS,OAAA,EACV,MAAM,IAAInB,UAAA,CAAW;IAEzB;EACF","ignoreList":[]}
1
+ {"version":3,"names":["AbortError","sleep","idleCb","requestIdleCallback","cb","setTimeout","idleAsync","Promise","res","idle","signal","options","max","min","fully","idleFn","fullyIdle","race","all","aborted","startTime","Date","now","endTime","duration"],"sources":["../../src/idle.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAC3B,SAASC,KAAA,QAAa;AAStB,MAAMC,MAAA,GACJ,OAAOC,mBAAA,KAAwB,cAC1BC,EAAA,IAAmBC,UAAA,CAAWD,EAAA,EAAI,CAAC,IACpCD,mBAAA;AAEN,MAAMG,SAAA,GAAYA,CAAA,KAAM;EACtB,OAAO,IAAIC,OAAA,CAASC,GAAA,IAAQ;IAC1BN,MAAA,CAAOM,GAAG;EACZ,CAAC;AACH;AAEO,MAAMC,IAAA,GAAO,MAAAA,CAClBC,MAAA,EACAC,OAAA,KAKkB;EAClB,MAAM;IAAEC,GAAA;IAAKC,GAAA;IAAKC;EAAM,IAAIH,OAAA,IAAW,CAAC;EAExC,MAAMI,MAAA,GAASD,KAAA,GAAQE,SAAA,GAAYV,SAAA;EAEnC,IAAIM,GAAA,IAAOC,GAAA,IAAOA,GAAA,GAAMD,GAAA,EAAK;IAC3B,MAAML,OAAA,CAAQU,IAAA,CAAK,CAACV,OAAA,CAAQW,GAAA,CAAI,CAACH,MAAA,CAAO,GAAGd,KAAA,CAAMY,GAAG,CAAC,CAAC,GAAGZ,KAAA,CAAMW,GAAG,CAAC,CAAC;EACtE,WAAWA,GAAA,EAAK;IACd,MAAML,OAAA,CAAQU,IAAA,CAAK,CAACF,MAAA,CAAO,GAAGd,KAAA,CAAMW,GAAG,CAAC,CAAC;EAC3C,WAAWC,GAAA,EAAK;IACd,MAAMN,OAAA,CAAQW,GAAA,CAAI,CAACH,MAAA,CAAO,GAAGd,KAAA,CAAMY,GAAG,CAAC,CAAC;EAC1C,OAAO;IACL,MAAME,MAAA,CAAO;EACf;EAEA,IAAIL,MAAA,EAAQS,OAAA,EAAS;IACnB,MAAM,IAAInB,UAAA,CAAW;EACvB;AACF;AAEA,MAAMgB,SAAA,GAAY,MAAON,MAAA,IAAwC;EAC/D,OAAO,MAAM;IACX,MAAMU,SAAA,GAAYC,IAAA,CAAKC,GAAA,CAAI;IAC3B,MAAMb,IAAA,CAAKC,MAAM;IACjB,MAAMa,OAAA,GAAUF,IAAA,CAAKC,GAAA,CAAI;IACzB,MAAME,QAAA,GAAWD,OAAA,GAAUH,SAAA;IAG3B,IAAII,QAAA,GAAW,IAAI;MACjB;IACF;IAGA,IAAId,MAAA,EAAQS,OAAA,EAAS;MACnB,MAAM,IAAInB,UAAA,CAAW;IACvB;EACF;AACF","ignoreList":[]}
@@ -1,31 +1,46 @@
1
1
  import { AbortError } from "./errors.native.js";
2
2
  import { sleep } from "./sleep.native.js";
3
- var idleCb = typeof requestIdleCallback > "u" ? function (cb) {
4
- return setTimeout(cb, 1);
5
- } : requestIdleCallback,
6
- idleAsync = function () {
7
- return new Promise(function (res) {
8
- idleCb(res);
9
- });
10
- },
11
- idle = async function (signal, options) {
12
- var {
13
- max,
14
- min,
15
- fully
16
- } = options || {},
17
- idleFn = fully ? fullyIdle : idleAsync;
18
- if (max && min && min < max ? await Promise.race([Promise.all([idleFn(), sleep(min)]), sleep(max)]) : max ? await Promise.race([idleFn(), sleep(max)]) : min ? await Promise.all([idleFn(), sleep(min)]) : await idleFn(), signal?.aborted) throw new AbortError();
19
- },
20
- fullyIdle = async function (signal) {
21
- for (;;) {
22
- var startTime = Date.now();
23
- await idle(signal);
24
- var endTime = Date.now(),
25
- duration = endTime - startTime;
26
- if (duration < 15) break;
27
- if (signal?.aborted) throw new AbortError();
3
+ var idleCb = typeof requestIdleCallback === "undefined" ? function (cb) {
4
+ return setTimeout(cb, 1);
5
+ } : requestIdleCallback;
6
+ var idleAsync = function () {
7
+ return new Promise(function (res) {
8
+ idleCb(res);
9
+ });
10
+ };
11
+ var idle = async function (signal, options) {
12
+ var {
13
+ max,
14
+ min,
15
+ fully
16
+ } = options || {};
17
+ var idleFn = fully ? fullyIdle : idleAsync;
18
+ if (max && min && min < max) {
19
+ await Promise.race([Promise.all([idleFn(), sleep(min)]), sleep(max)]);
20
+ } else if (max) {
21
+ await Promise.race([idleFn(), sleep(max)]);
22
+ } else if (min) {
23
+ await Promise.all([idleFn(), sleep(min)]);
24
+ } else {
25
+ await idleFn();
26
+ }
27
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
28
+ throw new AbortError();
29
+ }
30
+ };
31
+ var fullyIdle = async function (signal) {
32
+ while (true) {
33
+ var startTime = Date.now();
34
+ await idle(signal);
35
+ var endTime = Date.now();
36
+ var duration = endTime - startTime;
37
+ if (duration < 15) {
38
+ break;
28
39
  }
29
- };
40
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
41
+ throw new AbortError();
42
+ }
43
+ }
44
+ };
30
45
  export { idle };
31
46
  //# sourceMappingURL=idle.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["AbortError","sleep","idleCb","requestIdleCallback","cb","setTimeout","idleAsync","Promise","res","idle","signal","options","max","min","fully","idleFn","fullyIdle","race","all"],"sources":["../../src/idle.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAC3B,SAASC,KAAA,QAAa;AAStB,IAAAC,MAAM,UACJC,mBAAO,MAAwB,aAC1BC,EAAmB;IAKtB,OAAOC,UAAG,CAAAD,EAAA;EACZ,CAAC,GAGUD,mBACX;EAAAG,SACA,YAAAA,CAAA,EAKkB;IAClB,OAAM,IAAEC,OAAU,WAAUC,GAAA;MAc5BN,MAVI,CAAAM,GAAO;IAWT;EAEJ;EAEMC,IAAA,kBAAAA,CAAmBC,MAAA,EAAwCC,OAAA;IAC/D;QAAAC,GAAA;QAAaC,GAAA;QAAAC;MAAA,IAAAH,OAAA;MAAAI,MAAA,GAAAD,KAAA,GAAAE,SAAA,GAAAV,SAAA;IACX,IAAAM,GAAA,IAAMC,GAAA,IAAAA,GAAY,GAAAD,GAAK,GAAI,MAAAL,OAAA,CAAAU,IAAA,EAM3BV,OALA,CAAAW,GAAM,EAMJH,MAAA,IAIFd,KAAI,CAAAY,GAAA,CAAQ,CACV,GAEJZ,KAAA,CAAAW,GAAA,EACF,IAAAA,GAAA,SAAAL,OAAA,CAAAU,IAAA,E","ignoreList":[]}
1
+ {"version":3,"names":["AbortError","sleep","idleCb","requestIdleCallback","cb","setTimeout","idleAsync","Promise","res","idle","signal","options","max","min","fully","idleFn","fullyIdle","race","all","aborted"],"sources":["../../src/idle.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAC3B,SAASC,KAAA,QAAa;AAStB,IAAAC,MAAM,UACJC,mBAAO,gBAAwB,aAC1BC,EAAmB;EAG1B,OAAMC,UAAY,CAAAD,EAAA,EAAM;AACtB,IAAAD,mBAAoB;AAClB,IAAAG,SAAO,GAAG,SAAAA,CAAA;EACZ,OAAC,IAAAC,OAAA,WAAAC,GAAA;IACHN,MAAA,CAAAM,GAAA;EAEO;AAQL;AAEA,IAAAC,IAAM,kBAAAA,CAAiBC,MAAA,EAAAC,OAAY;EAEnC,IAAI;IAAAC,GAAA;IAAOC,GAAA;IAAAC;EAAO,IAAMH,OAAK;EAC3B,IAAAI,MAAM,GAAAD,KAAQ,GAAKE,SAAS,GAAAV,SAAY;EAC1C,IAAAM,GAAA,IAAWC,GAAA,IAAKA,GAAA,GAAAD,GAAA;IACd,MAAML,OAAA,CAAQU,IAAA,CAAK,CACrBV,OAAW,CAAAW,GAAA,CAAK,CACdH,MAAM,IACRd,KAAO,CAAAY,GAAA,EACL,GACFZ,KAAA,CAAAW,GAAA,EAEA,CAAI;EACF,WAAMA,GAAI;IACZ,MAAAL,OAAA,CAAAU,IAAA,EACFF,MAAA,IAEMd,KAAA,CAAAW,GAAA,EACJ;EACE,WAAMC,GAAA;IACN,MAAMN,OAAK,CAAAW,GAAM,EACjBH,MAAM,IACNd,KAAM,CAAAY,GAAA,EAGN;EACE;IACF,MAAAE,MAAA;EAGA;EACE,IAAAL,MAAM,KAAI,QAAAA,MAAW,uBAAAA,MAAA,CAAAS,OAAA;IACvB,UAAAnB,UAAA;EACF;AACF","ignoreList":[]}
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
- export * from "./useAsyncEffect";
2
- export * from "./sleep";
3
- export * from "./idle";
4
- export * from "./errors";
1
+ export * from "./useAsyncEffect.mjs";
2
+ export * from "./sleep.mjs";
3
+ export * from "./idle.mjs";
4
+ export * from "./errors.mjs";
5
5
  //# sourceMappingURL=index.js.map
@@ -1,6 +1 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/index.ts"],
4
- "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;",
5
- "names": []
6
- }
1
+ {"version":3,"names":[],"sources":["../../src/index.ts"],"sourcesContent":[null],"mappings":"AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc","ignoreList":[]}
@@ -1,6 +1,9 @@
1
1
  import { AbortError } from "./errors.mjs";
2
2
  const sleep = async (ms, signal) => {
3
- if (await new Promise(res => setTimeout(res, ms)), signal?.aborted) throw new AbortError();
3
+ await new Promise(res => setTimeout(res, ms));
4
+ if (signal?.aborted) {
5
+ throw new AbortError();
6
+ }
4
7
  };
5
8
  export { sleep };
6
9
  //# sourceMappingURL=sleep.mjs.map
@@ -1 +1 @@
1
- {"version":3,"names":["AbortError","sleep","ms","signal","Promise","res","setTimeout","aborted"],"sources":["../../src/sleep.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAEpB,MAAMC,KAAA,GAAQ,MAAAA,CAAOC,EAAA,EAAYC,MAAA,KAAwC;EAE9E,IADA,MAAM,IAAIC,OAAA,CAASC,GAAA,IAAQC,UAAA,CAAWD,GAAA,EAAKH,EAAE,CAAC,GAC1CC,MAAA,EAAQI,OAAA,EACV,MAAM,IAAIP,UAAA,CAAW;AAEzB","ignoreList":[]}
1
+ {"version":3,"names":["AbortError","sleep","ms","signal","Promise","res","setTimeout","aborted"],"sources":["../../src/sleep.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAEpB,MAAMC,KAAA,GAAQ,MAAAA,CAAOC,EAAA,EAAYC,MAAA,KAAwC;EAC9E,MAAM,IAAIC,OAAA,CAASC,GAAA,IAAQC,UAAA,CAAWD,GAAA,EAAKH,EAAE,CAAC;EAC9C,IAAIC,MAAA,EAAQI,OAAA,EAAS;IACnB,MAAM,IAAIP,UAAA,CAAW;EACvB;AACF","ignoreList":[]}
@@ -1,8 +1,11 @@
1
1
  import { AbortError } from "./errors.native.js";
2
2
  var sleep = async function (ms, signal) {
3
- if (await new Promise(function (res) {
3
+ await new Promise(function (res) {
4
4
  return setTimeout(res, ms);
5
- }), signal?.aborted) throw new AbortError();
5
+ });
6
+ if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
7
+ throw new AbortError();
8
+ }
6
9
  };
7
10
  export { sleep };
8
11
  //# sourceMappingURL=sleep.native.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["AbortError","sleep","ms","signal","Promise","res","setTimeout","aborted"],"sources":["../../src/sleep.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAEpB,IAAAC,KAAM,kBAAAA,CAA2BC,EAAA,EAAAC,MAAwC;EAE9E,IADA,MAAM,IAAIC,OAAA,CAAQ,UAASC,GAAA;IAEzB,OAAMC,UAAI,CAAAD,GAAW,EAAAH,EAAA;EAEzB,IAAAC,MAAA,EAAAI,OAAA,E","ignoreList":[]}
1
+ {"version":3,"names":["AbortError","sleep","ms","signal","Promise","res","setTimeout","aborted"],"sources":["../../src/sleep.ts"],"sourcesContent":[null],"mappings":"AAAA,SAASA,UAAA,QAAkB;AAEpB,IAAAC,KAAM,kBAAAA,CAA2BC,EAAA,EAAAC,MAAwC;EAC9E,MAAM,IAAIC,OAAA,CAAQ,UAASC,GAAA;IAC3B,OAAIC,UAAQ,CAAAD,GAAS,EAAAH,EAAA;EACnB;EACF,IAAAC,MAAA,aAAAA,MAAA,uBAAAA,MAAA,CAAAI,OAAA;IACF,UAAAP,UAAA","ignoreList":[]}
@@ -9,12 +9,12 @@ function useAsyncLayoutEffect(cb, deps = []) {
9
9
  }
10
10
  function useAsyncEffectOfType(type, cb, deps = []) {
11
11
  type(() => {
12
- const controller = new AbortController(),
13
- signal = controller.signal;
12
+ const controller = new AbortController();
13
+ const signal = controller.signal;
14
14
  try {
15
15
  const value = cb(signal, ...deps);
16
16
  Promise.resolve(value).then(async res => {
17
- if (res && typeof res == "function") {
17
+ if (res && typeof res === "function") {
18
18
  if (signal.aborted) return res();
19
19
  signal.addEventListener("abort", res);
20
20
  }
@@ -23,12 +23,20 @@ function useAsyncEffectOfType(type, cb, deps = []) {
23
23
  handleError(error);
24
24
  }
25
25
  function handleError(error) {
26
- if (error instanceof AbortError) return DEBUG_LEVEL > 2 && console.info(`\u{1F41B} useAsyncEffect aborted: ${error.message}`), null;
27
- if (typeof error == "object" && error.name === "AbortError") return null;
26
+ if (error instanceof AbortError) {
27
+ if (DEBUG_LEVEL > 2) {
28
+ console.info(`\u{1F41B} useAsyncEffect aborted: ${error.message}`);
29
+ }
30
+ return null;
31
+ }
32
+ if (typeof error === "object" && error.name === "AbortError") {
33
+ return null;
34
+ }
28
35
  throw error;
29
36
  }
30
37
  return () => {
31
- signal.aborted || controller.abort();
38
+ if (signal.aborted) return;
39
+ controller.abort();
32
40
  };
33
41
  }, deps);
34
42
  }