@evlop/commons 1.0.181 → 1.0.183

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,6 @@ import { Action } from './useActionable';
4
4
  * @param action action object ot function
5
5
  * @returns function
6
6
  */
7
- export declare const useAction: (action?: Action) => (event?: any) => any;
7
+ export declare const useAction: (action?: Action) => (event: any) => void;
8
8
  export default useAction;
9
9
  //# sourceMappingURL=useAction.d.ts.map
@@ -13,10 +13,10 @@ export interface ActionObject {
13
13
  callback: Function;
14
14
  }
15
15
  export declare type Action = ActionObject | Function | any;
16
- export declare const useActionableWithNavigator: (navigator: any) => (action: Action) => (event?: any) => any;
16
+ export declare const useActionableWithNavigator: (navigator: any) => (action: Action | Action[]) => (event: any) => void;
17
17
  /**
18
18
  * @description a function to map action into action handeller function
19
19
  */
20
- export declare const useActionable: () => (action: Action) => (event?: any) => any;
20
+ export declare const useActionable: () => (action: Action | Action[]) => (event: any) => void;
21
21
  export default useActionable;
22
22
  //# sourceMappingURL=useActionable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useActionable.d.ts","sourceRoot":"","sources":["../../../src/hooks/useActionable.tsx"],"names":[],"mappings":"AASA;;;;GAIG;AAEF,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IACjC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC5B,QAAQ,EAAE,QAAQ,CAAC;CACtB;AAED,oBAAY,MAAM,GAAG,YAAY,GAAG,QAAQ,GAAG,GAAG,CAAA;AAElD,eAAO,MAAM,0BAA0B,cAAe,GAAG,cAKF,MAAM,cAAc,GAAG,QA0B7E,CAAA;AAED;;GAEG;AACJ,eAAO,MAAM,aAAa,iBA/B8B,MAAM,cAAc,GAAG,QAmC9E,CAAC;AAEF,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"useActionable.d.ts","sourceRoot":"","sources":["../../../src/hooks/useActionable.tsx"],"names":[],"mappings":"AASA;;;;GAIG;AAEF,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IACjC,IAAI,EAAE,KAAK,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC;IAC7B,QAAQ,EAAE,MAAM,GAAG,QAAQ,CAAC;IAC5B,QAAQ,EAAE,QAAQ,CAAC;CACtB;AAED,oBAAY,MAAM,GAAG,YAAY,GAAG,QAAQ,GAAG,GAAG,CAAA;AAElD,eAAO,MAAM,0BAA0B,cAAe,GAAG,cAkCH,MAAM,GAAG,MAAM,EAAE,aAAa,GAAG,SAUtF,CAAA;AAED;;GAEG;AACJ,eAAO,MAAM,aAAa,iBAf6B,MAAM,GAAG,MAAM,EAAE,aAAa,GAAG,SAmBvF,CAAC;AAEF,eAAe,aAAa,CAAC"}
@@ -15,21 +15,27 @@ const useActionableWithNavigator = (navigator) => {
15
15
  const dispatch = react_redux_1.useDispatch();
16
16
  const scope = useScope_1.useScope();
17
17
  const template = useTemplate_1.default();
18
- const createActionHandeller = react_1.useCallback((action) => (event) => {
18
+ const handleAction = react_1.useCallback((action, event) => {
19
19
  let actionToUse = action;
20
- while (actionToUse && actionToUse.bindKey) {
21
- actionToUse = lodash_1.get(scope, actionToUse.bindKey);
20
+ let scopeActionName = typeof actionToUse === 'string' ? actionToUse : lodash_1.get(actionToUse, 'bindKey');
21
+ while (scopeActionName) {
22
+ actionToUse = lodash_1.get(scope, scopeActionName);
23
+ scopeActionName = typeof actionToUse === 'string' ? actionToUse : lodash_1.get(actionToUse, 'bindKey');
22
24
  }
23
25
  if (typeof actionToUse === 'function')
24
26
  return actionToUse(event);
25
- if (actionToUse) {
26
- const { link, navigate, push, page, params, dispatch: dispatchAction, route, callback } = actionToUse;
27
+ if (typeof actionToUse === 'object') {
28
+ const { link, navigate, replace, navigationAction, push, page, params, dispatch, reduxAction = dispatch, route, callback } = actionToUse;
27
29
  if (link)
28
30
  return navigator.openURL(template(link));
29
31
  if (navigate)
30
32
  return navigator.navigate(...lodash_1.castArray(JSON.parse(template(JSON.stringify(navigate)))));
33
+ if (replace)
34
+ return navigator.replace(...lodash_1.castArray(JSON.parse(template(JSON.stringify(replace)))));
31
35
  if (push)
32
36
  return navigator.push(...lodash_1.castArray(JSON.parse(template(JSON.stringify(push)))));
37
+ if (navigationAction)
38
+ return navigator.dispatch(JSON.parse(template(JSON.stringify(navigationAction))));
33
39
  if (page) {
34
40
  const routeParams = lodash_2.mapValues(params, (paramValue) => template(paramValue.toString()));
35
41
  return navigator.openPage(page, routeParams);
@@ -37,12 +43,20 @@ const useActionableWithNavigator = (navigator) => {
37
43
  ;
38
44
  if (route)
39
45
  return navigator.openRoute(template(route));
40
- if (dispatchAction)
41
- return dispatch(dispatchAction);
46
+ if (reduxAction)
47
+ return dispatch(reduxAction);
42
48
  if (callback)
43
49
  return callback({ event, navigator, dispatch });
44
50
  }
45
51
  }, [navigator, dispatch, template, scope]);
52
+ const createActionHandeller = react_1.useCallback((action) => (event) => {
53
+ if (Array.isArray(action)) {
54
+ // run all actions in sequence, if any action returns a promise, wait for it to resolve before running the next action
55
+ lodash_1.reduce(action, (promise, actionItem) => promise.then(() => handleAction(actionItem, event)), Promise.resolve());
56
+ return;
57
+ }
58
+ handleAction(action, event);
59
+ }, [handleAction]);
46
60
  return createActionHandeller;
47
61
  };
48
62
  exports.useActionableWithNavigator = useActionableWithNavigator;
@@ -1 +1 @@
1
- {"version":3,"file":"useActionable.js","sourceRoot":"","sources":["../../../src/hooks/useActionable.tsx"],"names":[],"mappings":";;;;;;AAAA,iCAA6C;AAC7C,6CAA0C;AAC1C,mCAAw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