@evlop/commons 1.0.227 → 1.0.228

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,5 +5,6 @@ import { Action } from './useActionable';
5
5
  * @returns function
6
6
  */
7
7
  export declare const useAction: (action?: Action) => (event: any) => void;
8
+ export declare const useAsyncAction: (action?: Action) => (boolean | ((event: any) => Promise<void>))[];
8
9
  export default useAction;
9
10
  //# sourceMappingURL=useAction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAction.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAction.tsx"],"names":[],"mappings":"AACA,OAAsB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGxD;;;;GAIG;AAEH,eAAO,MAAM,SAAS,YAAa,MAAM,yBAIxC,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"useAction.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAction.tsx"],"names":[],"mappings":"AACA,OAAsB,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAGxD;;;;GAIG;AAEH,eAAO,MAAM,SAAS,YAAa,MAAM,yBAIxC,CAAC;AAEF,eAAO,MAAM,cAAc,YAAa,MAAM,yBAMK,GAAG,sBAYrD,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -1,9 +1,18 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.useAction = void 0;
15
+ exports.useAsyncAction = exports.useAction = void 0;
7
16
  const react_1 = require("react");
8
17
  const useActionable_1 = __importDefault(require("./useActionable"));
9
18
  // link, callback, dispatch, navigate
@@ -17,5 +26,24 @@ const useAction = (action) => {
17
26
  return react_1.useMemo(() => action ? createActionHandeller(action) : null, [action, createActionHandeller]);
18
27
  };
19
28
  exports.useAction = useAction;
29
+ const useAsyncAction = (action) => {
30
+ const createActionHandeller = useActionable_1.default();
31
+ const [isProcessing, setIsProcessing] = react_1.useState(false);
32
+ const actionHandeller = react_1.useMemo(() => action ? createActionHandeller(action) : null, [action, createActionHandeller]);
33
+ const handleAction = react_1.useCallback((event) => __awaiter(void 0, void 0, void 0, function* () {
34
+ setIsProcessing(true);
35
+ try {
36
+ yield actionHandeller(event);
37
+ }
38
+ catch (error) {
39
+ console.error(error);
40
+ }
41
+ finally {
42
+ setIsProcessing(false);
43
+ }
44
+ }), [actionHandeller]);
45
+ return [isProcessing, handleAction];
46
+ };
47
+ exports.useAsyncAction = useAsyncAction;
20
48
  exports.default = exports.useAction;
21
49
  //# sourceMappingURL=useAction.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useAction.js","sourceRoot":"","sources":["../../../src/hooks/useAction.tsx"],"names":[],"mappings":";;;;;;AAAA,iCAAgC;AAChC,oEAAwD;AAExD,qCAAqC;AACrC;;;;GAIG;AAEI,MAAM,SAAS,GAAG,CAAC,MAAe,EAAC,EAAE;IACxC,MAAM,qBAAqB,GAAG,uBAAa,EAAE,CAAC;IAE9C,OAAO,eAAO,CAAC,GAAE,EAAE,CAAA,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC;AACvG,CAAC,CAAC;AAJW,QAAA,SAAS,aAIpB;AAEF,kBAAe,iBAAS,CAAC"}
1
+ {"version":3,"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;AAEF,kBAAe,iBAAS,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@evlop/commons",
3
- "version": "1.0.227",
3
+ "version": "1.0.228",
4
4
  "description": "",
5
5
  "main": "dist/main.js",
6
6
  "peerDependencies": {