@hairy/react-lib 1.20.0 → 1.22.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/dist/index.cjs CHANGED
@@ -207,6 +207,7 @@ var import_react7 = require("react");
207
207
  function useAsyncCallback(fun) {
208
208
  const [state, set] = (0, import_react7.useState)({ loading: false });
209
209
  async function execute(...args) {
210
+ set({ loading: true });
210
211
  return fun(...args).then((value) => {
211
212
  set({ loading: false });
212
213
  return value;
@@ -437,24 +438,21 @@ function track(action, status) {
437
438
  let loadings = 0;
438
439
  const tracking = () => loadings++ === 0 && (status.loading = true);
439
440
  const done = () => !--loadings && (status.loading = false);
440
- const fulfilled = () => {
441
+ const fulfilled = (value) => {
441
442
  status.finished = true;
442
443
  done();
444
+ return value;
443
445
  };
444
446
  const rejected = (error) => {
445
447
  status.error = error;
446
448
  done();
449
+ throw error;
447
450
  };
448
451
  return function(...args) {
449
452
  tracking();
450
453
  try {
451
- const result = action(...args);
452
- if (result instanceof Promise) {
453
- return result.then(fulfilled).catch(rejected);
454
- } else {
455
- fulfilled();
456
- return result;
457
- }
454
+ const value = action(...args);
455
+ return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
458
456
  } catch (error) {
459
457
  rejected(error);
460
458
  }
@@ -310,6 +310,7 @@ var LibReact = (() => {
310
310
  function useAsyncCallback(fun) {
311
311
  const [state, set] = (0, import_react7.useState)({ loading: false });
312
312
  async function execute(...args) {
313
+ set({ loading: true });
313
314
  return fun(...args).then((value) => {
314
315
  set({ loading: false });
315
316
  return value;
@@ -1115,24 +1116,21 @@ var LibReact = (() => {
1115
1116
  let loadings = 0;
1116
1117
  const tracking = () => loadings++ === 0 && (status.loading = true);
1117
1118
  const done = () => !--loadings && (status.loading = false);
1118
- const fulfilled = () => {
1119
+ const fulfilled = (value) => {
1119
1120
  status.finished = true;
1120
1121
  done();
1122
+ return value;
1121
1123
  };
1122
1124
  const rejected = (error) => {
1123
1125
  status.error = error;
1124
1126
  done();
1127
+ throw error;
1125
1128
  };
1126
1129
  return function(...args) {
1127
1130
  tracking();
1128
1131
  try {
1129
- const result = action(...args);
1130
- if (result instanceof Promise) {
1131
- return result.then(fulfilled).catch(rejected);
1132
- } else {
1133
- fulfilled();
1134
- return result;
1135
- }
1132
+ const value = action(...args);
1133
+ return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
1136
1134
  } catch (error) {
1137
1135
  rejected(error);
1138
1136
  }
package/dist/index.js CHANGED
@@ -147,6 +147,7 @@ import { useState } from "react";
147
147
  function useAsyncCallback(fun) {
148
148
  const [state, set] = useState({ loading: false });
149
149
  async function execute(...args) {
150
+ set({ loading: true });
150
151
  return fun(...args).then((value) => {
151
152
  set({ loading: false });
152
153
  return value;
@@ -377,24 +378,21 @@ function track(action, status) {
377
378
  let loadings = 0;
378
379
  const tracking = () => loadings++ === 0 && (status.loading = true);
379
380
  const done = () => !--loadings && (status.loading = false);
380
- const fulfilled = () => {
381
+ const fulfilled = (value) => {
381
382
  status.finished = true;
382
383
  done();
384
+ return value;
383
385
  };
384
386
  const rejected = (error) => {
385
387
  status.error = error;
386
388
  done();
389
+ throw error;
387
390
  };
388
391
  return function(...args) {
389
392
  tracking();
390
393
  try {
391
- const result = action(...args);
392
- if (result instanceof Promise) {
393
- return result.then(fulfilled).catch(rejected);
394
- } else {
395
- fulfilled();
396
- return result;
397
- }
394
+ const value = action(...args);
395
+ return value instanceof Promise ? value.then(fulfilled, rejected) : fulfilled(value);
398
396
  } catch (error) {
399
397
  rejected(error);
400
398
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hairy/react-lib",
3
3
  "type": "module",
4
- "version": "1.20.0",
4
+ "version": "1.22.0",
5
5
  "description": "Library for react",
6
6
  "author": "Hairyf <wwu710632@gmail.com>",
7
7
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  "react-dom": "^18.2.0",
39
39
  "react-i18next": "^14.1.2",
40
40
  "react-use": "^17.6.0",
41
- "@hairy/utils": "1.20.0"
41
+ "@hairy/utils": "1.22.0"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "tsup",