@mic-rexjs/usecases-react 1.3.35 → 1.4.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.
Files changed (85) hide show
  1. package/dist/index.min.js +1 -1
  2. package/es/components/UpdateFragment/index.d.ts +2 -0
  3. package/es/components/UpdateFragment/index.js +8 -0
  4. package/es/components/UpdateFragment/types.d.ts +3 -0
  5. package/es/components/UseCaseFragment/index.d.ts +1 -1
  6. package/es/components/UseCaseFragment/types.d.ts +2 -2
  7. package/es/configs/defaultUseCaseContext/index.d.ts +3 -1
  8. package/es/configs/defaultUseCaseContext/index.js +1 -1
  9. package/es/configs/defaultUseCaseContext/types.d.ts +11 -0
  10. package/es/configs/defaultUseCaseContext/types.js +1 -0
  11. package/es/configs/usecaseContextMap/index.d.ts +1 -3
  12. package/es/configs/usecaseContextMap/types.d.ts +4 -17
  13. package/es/hooks/useCompareDeps/index.d.ts +1 -0
  14. package/es/hooks/useCompareDeps/index.js +24 -0
  15. package/es/hooks/useConstant/index.d.ts +2 -0
  16. package/es/hooks/useConstant/index.js +5 -0
  17. package/es/hooks/useConstant/types.d.ts +3 -0
  18. package/es/hooks/useConstant/types.js +1 -0
  19. package/es/hooks/useConstantFn/index.d.ts +1 -0
  20. package/es/hooks/useConstantFn/index.js +7 -0
  21. package/es/hooks/useOptionsRefCollection/index.d.ts +3 -0
  22. package/es/hooks/useOptionsRefCollection/index.js +22 -0
  23. package/es/hooks/useOptionsRefCollection/types.d.ts +2 -0
  24. package/es/hooks/useOptionsRefCollection/types.js +1 -0
  25. package/es/hooks/useProvider/index.d.ts +7 -0
  26. package/es/hooks/useProvider/index.js +17 -0
  27. package/es/hooks/useProvider/types.d.ts +3 -0
  28. package/es/hooks/useProvider/types.js +1 -0
  29. package/es/hooks/useScope/index.d.ts +2 -0
  30. package/es/hooks/useScope/index.js +3 -0
  31. package/es/hooks/useScope/types.d.ts +3 -0
  32. package/es/hooks/useScope/types.js +1 -0
  33. package/es/hooks/useUseCase/index.js +68 -89
  34. package/es/hooks/useUseCase/index.test.js +166 -136
  35. package/es/hooks/useUseCase/types.d.ts +9 -7
  36. package/es/hooks/useUseCaseContext/index.d.ts +3 -0
  37. package/es/hooks/useUseCaseContext/index.js +17 -0
  38. package/es/index.d.ts +3 -2
  39. package/es/methods/getRootEntity/index.d.ts +2 -0
  40. package/es/methods/getRootEntity/index.js +9 -0
  41. package/es/methods/initEntityReducers/index.d.ts +5 -0
  42. package/es/methods/initEntityReducers/index.js +13 -0
  43. package/es/methods/initEntityReducers/types.d.ts +3 -0
  44. package/es/methods/initEntityReducers/types.js +1 -0
  45. package/es/methods/removeItem/index.d.ts +1 -0
  46. package/es/methods/removeItem/index.js +7 -0
  47. package/es/methods/triggerCallbacks/index.d.ts +3 -0
  48. package/es/methods/triggerCallbacks/index.js +14 -0
  49. package/es/{hooks/useUseCase/methods → methods}/triggerWatchers/index.d.ts +1 -1
  50. package/lib/components/UpdateFragment/index.js +16 -0
  51. package/lib/configs/defaultUseCaseContext/index.js +1 -1
  52. package/lib/configs/defaultUseCaseContext/types.js +5 -0
  53. package/lib/hooks/useCompareDeps/index.js +31 -0
  54. package/lib/hooks/useConstant/index.js +16 -0
  55. package/lib/hooks/useConstant/types.js +5 -0
  56. package/lib/hooks/useConstantFn/index.js +18 -0
  57. package/lib/hooks/useOptionsRefCollection/index.js +29 -0
  58. package/lib/hooks/useOptionsRefCollection/types.js +5 -0
  59. package/lib/hooks/useProvider/index.js +30 -0
  60. package/lib/hooks/useProvider/types.js +5 -0
  61. package/lib/hooks/useScope/index.js +10 -0
  62. package/lib/hooks/useScope/types.js +5 -0
  63. package/lib/hooks/useUseCase/index.js +73 -115
  64. package/lib/hooks/useUseCase/index.test.js +226 -177
  65. package/lib/hooks/useUseCaseContext/index.js +24 -0
  66. package/lib/methods/getRootEntity/index.js +16 -0
  67. package/lib/methods/initEntityReducers/index.js +29 -0
  68. package/lib/methods/initEntityReducers/types.js +5 -0
  69. package/lib/methods/removeItem/index.js +14 -0
  70. package/lib/methods/triggerCallbacks/index.js +22 -0
  71. package/package.json +2 -2
  72. package/es/core/usecases/optionsGetterCellectionUseCase/index.d.ts +0 -2
  73. package/es/core/usecases/optionsGetterCellectionUseCase/index.js +0 -13
  74. package/es/core/usecases/optionsGetterCellectionUseCase/types.d.ts +0 -8
  75. package/es/hooks/useOptionsTransfer/index.d.ts +0 -3
  76. package/es/hooks/useOptionsTransfer/index.js +0 -15
  77. package/es/hooks/useUseCase/methods/triggerCallbacks/index.d.ts +0 -3
  78. package/es/hooks/useUseCase/methods/triggerCallbacks/index.js +0 -11
  79. package/lib/core/usecases/optionsGetterCellectionUseCase/index.js +0 -23
  80. package/lib/hooks/useOptionsTransfer/index.js +0 -23
  81. package/lib/hooks/useUseCase/methods/triggerCallbacks/index.js +0 -32
  82. /package/es/{core/usecases/optionsGetterCellectionUseCase → components/UpdateFragment}/types.js +0 -0
  83. /package/es/{hooks/useUseCase/methods → methods}/triggerWatchers/index.js +0 -0
  84. /package/lib/{core/usecases/optionsGetterCellectionUseCase → components/UpdateFragment}/types.js +0 -0
  85. /package/lib/{hooks/useUseCase/methods → methods}/triggerWatchers/index.js +0 -0
@@ -1,15 +0,0 @@
1
- import { useCreation, useMemoizedFn, usePrevious, useUnmount } from 'ahooks';
2
- export const useOptionsTransfer = (options, optionsGetterListReducers) => {
3
- const { addOptionsGetter, removeOptionsGetter } = optionsGetterListReducers;
4
- const prevRemoveOptionsGetter = usePrevious(removeOptionsGetter);
5
- const getOptions = useMemoizedFn(() => {
6
- return options;
7
- });
8
- useCreation(() => {
9
- prevRemoveOptionsGetter?.(getOptions);
10
- addOptionsGetter(getOptions);
11
- }, [addOptionsGetter, prevRemoveOptionsGetter, getOptions]);
12
- useUnmount(() => {
13
- removeOptionsGetter(getOptions);
14
- });
15
- };
@@ -1,3 +0,0 @@
1
- import { OptionsGetter } from '../../../../core/usecases/optionsGetterCellectionUseCase/types';
2
- import { UseCaseHookOptions } from '../../types';
3
- export declare const triggerCallbacks: <T, TOptions extends object>(getterList: OptionsGetter<UseCaseHookOptions<T, TOptions>>[], newEntity: T, prevEntity: T) => void;
@@ -1,11 +0,0 @@
1
- import { triggerWatchers } from '../triggerWatchers';
2
- export const triggerCallbacks = (getterList, newEntity, prevEntity) => {
3
- for (const getter of getterList) {
4
- const { onChange, watch } = getter();
5
- onChange?.(newEntity, prevEntity);
6
- if (!watch) {
7
- continue;
8
- }
9
- triggerWatchers(watch, newEntity, prevEntity);
10
- }
11
- };
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.optionsGetterCollectionUseCase = void 0;
7
- var optionsGetterCollectionUseCase = function optionsGetterCollectionUseCase(collection) {
8
- var addOptionsGetter = function addOptionsGetter(getter) {
9
- collection.unshift(getter);
10
- };
11
- var removeOptionsGetter = function removeOptionsGetter(getter) {
12
- var index = collection.indexOf(getter);
13
- if (index === -1) {
14
- return;
15
- }
16
- collection.splice(index, 1);
17
- };
18
- return {
19
- addOptionsGetter: addOptionsGetter,
20
- removeOptionsGetter: removeOptionsGetter
21
- };
22
- };
23
- exports.optionsGetterCollectionUseCase = optionsGetterCollectionUseCase;
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useOptionsTransfer = void 0;
7
- var _ahooks = require("ahooks");
8
- var useOptionsTransfer = function useOptionsTransfer(options, optionsGetterListReducers) {
9
- var addOptionsGetter = optionsGetterListReducers.addOptionsGetter,
10
- removeOptionsGetter = optionsGetterListReducers.removeOptionsGetter;
11
- var prevRemoveOptionsGetter = (0, _ahooks.usePrevious)(removeOptionsGetter);
12
- var getOptions = (0, _ahooks.useMemoizedFn)(function () {
13
- return options;
14
- });
15
- (0, _ahooks.useCreation)(function () {
16
- prevRemoveOptionsGetter === null || prevRemoveOptionsGetter === void 0 ? void 0 : prevRemoveOptionsGetter(getOptions);
17
- addOptionsGetter(getOptions);
18
- }, [addOptionsGetter, prevRemoveOptionsGetter, getOptions]);
19
- (0, _ahooks.useUnmount)(function () {
20
- removeOptionsGetter(getOptions);
21
- });
22
- };
23
- exports.useOptionsTransfer = useOptionsTransfer;
@@ -1,32 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.triggerCallbacks = void 0;
7
- var _triggerWatchers = require("../triggerWatchers");
8
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
9
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
- var triggerCallbacks = function triggerCallbacks(getterList, newEntity, prevEntity) {
12
- var _iterator = _createForOfIteratorHelper(getterList),
13
- _step;
14
- try {
15
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
16
- var getter = _step.value;
17
- var _getter = getter(),
18
- onChange = _getter.onChange,
19
- watch = _getter.watch;
20
- onChange === null || onChange === void 0 ? void 0 : onChange(newEntity, prevEntity);
21
- if (!watch) {
22
- continue;
23
- }
24
- (0, _triggerWatchers.triggerWatchers)(watch, newEntity, prevEntity);
25
- }
26
- } catch (err) {
27
- _iterator.e(err);
28
- } finally {
29
- _iterator.f();
30
- }
31
- };
32
- exports.triggerCallbacks = triggerCallbacks;