@mic-rexjs/usecases-react 2.10.2 → 2.11.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 (98) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/index.min.js.LICENSE.txt +4 -2
  3. package/es/components/SafeUseCaseFragment/index.js +1 -1
  4. package/es/components/UseCaseFragment/index.js +2 -2
  5. package/es/components/UseCaseFragment/types.d.ts +1 -1
  6. package/es/entities/matchPropertyFailedResult/types.d.ts +7 -0
  7. package/es/hooks/useArgumentTypes/index.d.ts +1 -1
  8. package/es/hooks/useArgumentTypes/index.js +3 -4
  9. package/es/hooks/useConstantEntityReducers/index.d.ts +3 -0
  10. package/es/hooks/useConstantEntityReducers/index.js +7 -0
  11. package/es/hooks/useConstantReducers/index.d.ts +3 -0
  12. package/es/hooks/useConstantReducers/index.js +6 -0
  13. package/es/hooks/useContext/index.d.ts +2 -2
  14. package/es/hooks/useContext/index.test.js +2 -2
  15. package/es/hooks/useContextualItem/index.d.ts +3 -2
  16. package/es/hooks/useContextualItem/index.js +18 -8
  17. package/es/hooks/useDepsKey/index.d.ts +2 -0
  18. package/es/hooks/useDepsKey/index.js +7 -0
  19. package/es/hooks/useEntity/index.d.ts +3 -2
  20. package/es/hooks/useEntity/index.js +17 -9
  21. package/es/hooks/useFullArguments/index.d.ts +3 -3
  22. package/es/hooks/useFullArguments/types.d.ts +5 -4
  23. package/es/hooks/useIsRenderingRef/index.js +3 -3
  24. package/es/hooks/useProvider/index.d.ts +3 -3
  25. package/es/hooks/useProvider/index.js +3 -3
  26. package/es/hooks/useProvider/types.d.ts +0 -1
  27. package/es/hooks/useRuntimeEntity/index.d.ts +3 -2
  28. package/es/hooks/useRuntimeEntity/index.js +8 -6
  29. package/es/hooks/useStatuses/index.d.ts +2 -2
  30. package/es/hooks/useStatuses/index.js +1 -1
  31. package/es/hooks/useUseCase/index.js +22 -16
  32. package/es/hooks/useUseCase/index.test.js +70 -6
  33. package/es/hooks/useUseCase/types.d.ts +13 -16
  34. package/es/methods/triggerWatchers/index.js +4 -9
  35. package/es/types.d.ts +3 -0
  36. package/es/usecases/contextUseCase/index.js +1 -1
  37. package/es/usecases/contextUseCase/types.d.ts +2 -3
  38. package/es/usecases/methodUseCase/index.d.ts +2 -0
  39. package/es/usecases/methodUseCase/index.js +55 -0
  40. package/es/usecases/methodUseCase/types.d.ts +21 -0
  41. package/es/usecases/valueUseCase/index.d.ts +2 -0
  42. package/es/usecases/valueUseCase/index.js +172 -0
  43. package/es/usecases/valueUseCase/types.d.ts +20 -0
  44. package/es/usecases/valueUseCase/types.js +1 -0
  45. package/lib/components/SafeUseCaseFragment/index.js +1 -1
  46. package/lib/components/UseCaseFragment/index.js +2 -2
  47. package/lib/hooks/useArgumentTypes/index.js +3 -4
  48. package/lib/hooks/useConstantEntityReducers/index.js +13 -0
  49. package/lib/hooks/useConstantReducers/index.js +12 -0
  50. package/lib/hooks/useContext/index.test.js +2 -2
  51. package/lib/hooks/useContextualItem/index.js +18 -7
  52. package/lib/hooks/useDepsKey/index.js +18 -0
  53. package/lib/hooks/useEntity/index.js +21 -10
  54. package/lib/hooks/useIsRenderingRef/index.js +2 -2
  55. package/lib/hooks/useProvider/index.js +4 -6
  56. package/lib/hooks/useRuntimeEntity/index.js +10 -6
  57. package/lib/hooks/useStatuses/index.js +1 -1
  58. package/lib/hooks/useUseCase/index.js +30 -19
  59. package/lib/hooks/useUseCase/index.test.js +242 -158
  60. package/lib/methods/triggerWatchers/index.js +5 -9
  61. package/lib/usecases/contextUseCase/index.js +1 -1
  62. package/lib/usecases/methodUseCase/index.js +79 -0
  63. package/lib/usecases/valueUseCase/index.js +246 -0
  64. package/lib/usecases/valueUseCase/types.js +5 -0
  65. package/package.json +45 -40
  66. package/es/hooks/useCompareDeps/index.d.ts +0 -1
  67. package/es/hooks/useCompareDeps/index.js +0 -11
  68. package/es/methods/cacheCall/index.d.ts +0 -2
  69. package/es/methods/cacheCall/index.js +0 -26
  70. package/es/methods/cacheCall/types.d.ts +0 -13
  71. package/es/methods/cacheCalls/index.d.ts +0 -2
  72. package/es/methods/cacheCalls/index.js +0 -8
  73. package/es/methods/captureCalls/index.d.ts +0 -2
  74. package/es/methods/captureCalls/index.js +0 -14
  75. package/es/methods/captureCalls/types.d.ts +0 -4
  76. package/es/methods/compareProperty/index.d.ts +0 -2
  77. package/es/methods/compareProperty/index.js +0 -34
  78. package/es/methods/compareProperty/types.d.ts +0 -3
  79. package/es/methods/hasField/index.d.ts +0 -1
  80. package/es/methods/hasField/index.js +0 -6
  81. package/es/methods/initEntityReducers/index.d.ts +0 -5
  82. package/es/methods/initEntityReducers/index.js +0 -11
  83. package/es/methods/isSameArray/index.d.ts +0 -1
  84. package/es/methods/isSameArray/index.js +0 -14
  85. package/lib/hooks/useCompareDeps/index.js +0 -17
  86. package/lib/methods/cacheCall/index.js +0 -41
  87. package/lib/methods/cacheCalls/index.js +0 -19
  88. package/lib/methods/captureCalls/index.js +0 -23
  89. package/lib/methods/compareProperty/index.js +0 -49
  90. package/lib/methods/hasField/index.js +0 -14
  91. package/lib/methods/initEntityReducers/index.js +0 -24
  92. package/lib/methods/isSameArray/index.js +0 -20
  93. /package/es/{methods/cacheCall → entities/matchPropertyFailedResult}/types.js +0 -0
  94. /package/es/{methods/captureCalls/types.js → types.js} +0 -0
  95. /package/es/{methods/compareProperty → usecases/methodUseCase}/types.js +0 -0
  96. /package/lib/{methods/cacheCall → entities/matchPropertyFailedResult}/types.js +0 -0
  97. /package/lib/{methods/captureCalls/types.js → types.js} +0 -0
  98. /package/lib/{methods/compareProperty → usecases/methodUseCase}/types.js +0 -0
@@ -6,20 +6,16 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.triggerWatchers = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
- var _compareProperty = require("../compareProperty");
9
+ var _valueUseCase2 = require("../../usecases/valueUseCase");
10
10
  var triggerWatchers = exports.triggerWatchers = function triggerWatchers(watch, newEntity, oldEntity) {
11
+ var _valueUseCase = (0, _valueUseCase2.valueUseCase)(),
12
+ matchProperty = _valueUseCase.matchProperty;
11
13
  var _loop = function _loop() {
12
14
  var _Object$entries$_i = (0, _slicedToArray2["default"])(_Object$entries[_i], 2),
13
15
  fieldPath = _Object$entries$_i[0],
14
16
  watcher = _Object$entries$_i[1];
15
- (0, _compareProperty.compareProperty)(oldEntity, newEntity, fieldPath, function (oldValue, newValue, fieldPaths) {
16
- watcher({
17
- fieldPaths: fieldPaths,
18
- newEntity: newEntity,
19
- oldEntity: oldEntity,
20
- newValue: newValue,
21
- oldValue: oldValue
22
- });
17
+ matchProperty(oldEntity, newEntity, fieldPath, function (result) {
18
+ watcher(result);
23
19
  });
24
20
  };
25
21
  for (var _i = 0, _Object$entries = Object.entries(watch); _i < _Object$entries.length; _i++) {
@@ -5,8 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.contextUseCase = void 0;
7
7
  var _usecases = require("@mic-rexjs/usecases");
8
- var _ArgumentTypes = require("../../enums/ArgumentTypes");
9
8
  var _react = require("react");
9
+ var _ArgumentTypes = require("../../enums/ArgumentTypes");
10
10
  var _Statuses = require("../../enums/Statuses");
11
11
  var contextUseCase = exports.contextUseCase = (0, _usecases.createUseCase)(function () {
12
12
  var referenceMap = new Map();
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.methodUseCase = void 0;
8
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
+ var _valueUseCase2 = require("../valueUseCase");
10
+ var methodUseCase = exports.methodUseCase = function methodUseCase() {
11
+ var _valueUseCase = (0, _valueUseCase2.valueUseCase)(),
12
+ isValueMatched = _valueUseCase.isValueMatched;
13
+ var cacheCall = function cacheCall(factory, options) {
14
+ var cache;
15
+ var _ref = options || {},
16
+ _ref$onShouldCache = _ref.onShouldCache,
17
+ onShouldCache = _ref$onShouldCache === void 0 ? function () {
18
+ return true;
19
+ } : _ref$onShouldCache,
20
+ _ref$onCompare = _ref.onCompare,
21
+ onCompare = _ref$onCompare === void 0 ? function (newArgs, oldArgs) {
22
+ return isValueMatched(newArgs, oldArgs);
23
+ } : _ref$onCompare;
24
+ return function () {
25
+ var cacheable = onShouldCache();
26
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
27
+ args[_key] = arguments[_key];
28
+ }
29
+ if (cache && cacheable) {
30
+ var _cache = cache,
31
+ parameters = _cache.parameters,
32
+ _returnValue = _cache.returnValue;
33
+ if (onCompare(parameters, args)) {
34
+ return _returnValue;
35
+ }
36
+ }
37
+ var returnValue = factory.apply(void 0, args);
38
+ if (cacheable) {
39
+ cache = {
40
+ parameters: args,
41
+ returnValue: returnValue
42
+ };
43
+ }
44
+ return returnValue;
45
+ };
46
+ };
47
+ var cacheCalls = function cacheCalls(sourceFactories, options) {
48
+ var cachedFactories = {};
49
+ Object.entries(sourceFactories).forEach(function (_ref2) {
50
+ var _ref3 = (0, _slicedToArray2["default"])(_ref2, 2),
51
+ key = _ref3[0],
52
+ factory = _ref3[1];
53
+ cachedFactories[key] = cacheCall(factory, options);
54
+ });
55
+ return cachedFactories;
56
+ };
57
+ var captureCalls = function captureCalls(obj, callback) {
58
+ var newObj = {};
59
+ Object.keys(obj).forEach(function (key) {
60
+ var value = obj[key];
61
+ if (typeof value === 'function') {
62
+ newObj[key] = function () {
63
+ for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
64
+ args[_key2] = arguments[_key2];
65
+ }
66
+ return callback(key, args);
67
+ };
68
+ return;
69
+ }
70
+ newObj[key] = value;
71
+ });
72
+ return newObj;
73
+ };
74
+ return {
75
+ cacheCall: cacheCall,
76
+ cacheCalls: cacheCalls,
77
+ captureCalls: captureCalls
78
+ };
79
+ };
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.valueUseCase = void 0;
8
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
13
+ var _usecases = require("@mic-rexjs/usecases");
14
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
15
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2["default"])(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
16
+ var valueUseCase = exports.valueUseCase = (0, _usecases.createUseCase)(function () {
17
+ var keyIndex = 0;
18
+ return function () {
19
+ var prevKeyIndex = keyIndex++;
20
+ var entityReducers = (0, _usecases.entityUseCase)();
21
+ var hasField = function hasField(entity, field) {
22
+ if ((0, _typeof2["default"])(entity) !== 'object' || entity === null) {
23
+ return false;
24
+ }
25
+ return Object.hasOwn(entity, field);
26
+ };
27
+ var isValueChanged = function isValueChanged(entity, value) {
28
+ return entity !== value;
29
+ };
30
+ var isValueMatched = function isValueMatched(entity, value, onMatchFailed) {
31
+ if (entity === value) {
32
+ return true;
33
+ }
34
+ var isObject1 = (0, _typeof2["default"])(entity) === 'object' && entity !== null;
35
+ var isObject2 = (0, _typeof2["default"])(value) === 'object' && value !== null;
36
+ if (!isObject1 || !isObject2) {
37
+ return false;
38
+ }
39
+ var allMatched = true;
40
+ var keys1 = Object.keys(entity);
41
+ var keys2 = Object.keys(value);
42
+ var length1 = keys1.length;
43
+ var keys = [].concat(keys1, keys2);
44
+ var hasCallback = typeof onMatchFailed === 'function';
45
+ for (var i = 0, length = keys.length; i < length; i++) {
46
+ var key = keys[i];
47
+ var isFromKeys2 = i >= length1;
48
+ var isInKey1 = keys1.includes(key);
49
+ var isUsed = isFromKeys2 && isInKey1;
50
+ if (isUsed) {
51
+ continue;
52
+ }
53
+ var hasField1 = Object.hasOwn(entity, key);
54
+ var hasField2 = Object.hasOwn(value, key);
55
+ var onlyHasField1 = hasField1 && !hasField2;
56
+ var onlyHasField2 = !hasField1 && hasField2;
57
+ var onlyHasOneField = onlyHasField1 || onlyHasField2;
58
+ var value1 = entity[key];
59
+ var value2 = value[key];
60
+ var matched = value1 === value2;
61
+ if (!onlyHasOneField && matched) {
62
+ continue;
63
+ }
64
+ allMatched = false;
65
+ if (hasCallback) {
66
+ onMatchFailed(key, value2, value1);
67
+ continue;
68
+ }
69
+ break;
70
+ }
71
+ return allMatched;
72
+ };
73
+ var matchProperty = function matchProperty(entity, value, fieldPath, onFailed) {
74
+ var allMatched = true;
75
+ var currentFieldPath = fieldPath;
76
+ var list = [{
77
+ fieldPaths: [],
78
+ newEntity: value,
79
+ newValue: value,
80
+ oldEntity: entity,
81
+ oldValue: entity
82
+ }];
83
+ do {
84
+ var _list$shift = list.shift(),
85
+ oldValue = _list$shift.oldValue,
86
+ newValue = _list$shift.newValue,
87
+ fieldPaths = _list$shift.fieldPaths;
88
+ var _ref = currentFieldPath.match(/^([^.]+)\.(.+)$/) || [],
89
+ _ref2 = (0, _slicedToArray2["default"])(_ref, 3),
90
+ _ref2$ = _ref2[1],
91
+ key = _ref2$ === void 0 ? currentFieldPath : _ref2$,
92
+ _ref2$2 = _ref2[2],
93
+ subFieldPath = _ref2$2 === void 0 ? '' : _ref2$2;
94
+ var hasOldField = hasField(oldValue, key);
95
+ var hasNewField = hasField(newValue, key);
96
+ if (hasOldField || hasNewField) {
97
+ var subOldValue = hasOldField ? oldValue[key] : void 0;
98
+ var subNewValue = hasNewField ? newValue[key] : void 0;
99
+ var result = {
100
+ fieldPaths: [].concat((0, _toConsumableArray2["default"])(fieldPaths), [key]),
101
+ newEntity: value,
102
+ newValue: subNewValue,
103
+ oldEntity: entity,
104
+ oldValue: subOldValue
105
+ };
106
+ if (subFieldPath) {
107
+ currentFieldPath = subFieldPath;
108
+ list.push(result);
109
+ continue;
110
+ }
111
+ if (subOldValue === subNewValue) {
112
+ continue;
113
+ }
114
+ allMatched = false;
115
+ onFailed === null || onFailed === void 0 || onFailed(result);
116
+ continue;
117
+ }
118
+ if (/^\d+^/.test(key)) {
119
+ continue;
120
+ }
121
+ var oldArray = Array.isArray(oldValue) ? oldValue : [];
122
+ var newArray = Array.isArray(newValue) ? newValue : [];
123
+ var oldLength = oldArray.length;
124
+ var newLength = newArray.length;
125
+ var length = Math.max(oldLength, newLength);
126
+ for (var i = 0; i < length; i++) {
127
+ list.push({
128
+ fieldPaths: [].concat((0, _toConsumableArray2["default"])(fieldPaths), ["".concat(i)]),
129
+ newEntity: value,
130
+ newValue: newArray[i],
131
+ oldEntity: entity,
132
+ oldValue: oldArray[i]
133
+ });
134
+ }
135
+ } while (list.length > 0);
136
+ return allMatched;
137
+ };
138
+ var recordValue = /*#__PURE__*/_regenerator["default"].mark(function recordValue(entity, value) {
139
+ var changed;
140
+ return _regenerator["default"].wrap(function (_context) {
141
+ while (1) switch (_context.prev = _context.next) {
142
+ case 0:
143
+ changed = isValueChanged(entity, value);
144
+ if (changed) {
145
+ _context.next = 1;
146
+ break;
147
+ }
148
+ return _context.abrupt("return", false);
149
+ case 1:
150
+ _context.next = 2;
151
+ return value;
152
+ case 2:
153
+ return _context.abrupt("return", true);
154
+ case 3:
155
+ case "end":
156
+ return _context.stop();
157
+ }
158
+ }, recordValue);
159
+ });
160
+ var recordValueDiff = /*#__PURE__*/_regenerator["default"].mark(function recordValueDiff(entity, value) {
161
+ var isArray1, isArray2, isArray, result, length1, length2, matched;
162
+ return _regenerator["default"].wrap(function (_context2) {
163
+ while (1) switch (_context2.prev = _context2.next) {
164
+ case 0:
165
+ isArray1 = Array.isArray(entity);
166
+ isArray2 = Array.isArray(value);
167
+ isArray = isArray1 && isArray2;
168
+ result = isArray ? [] : {};
169
+ if (isArray) {
170
+ length1 = entity.length;
171
+ length2 = value.length;
172
+ result.length = Math.max(length1, length2);
173
+ }
174
+ matched = isValueMatched(entity, value, function (key, newValue) {
175
+ result[key] = newValue;
176
+ });
177
+ if (matched) {
178
+ _context2.next = 1;
179
+ break;
180
+ }
181
+ _context2.next = 1;
182
+ return value;
183
+ case 1:
184
+ return _context2.abrupt("return", result);
185
+ case 2:
186
+ case "end":
187
+ return _context2.stop();
188
+ }
189
+ }, recordValueDiff);
190
+ });
191
+ var recordValueMatch = /*#__PURE__*/_regenerator["default"].mark(function recordValueMatch(entity, value) {
192
+ var matched;
193
+ return _regenerator["default"].wrap(function (_context3) {
194
+ while (1) switch (_context3.prev = _context3.next) {
195
+ case 0:
196
+ matched = isValueMatched(entity, value);
197
+ if (!matched) {
198
+ _context3.next = 1;
199
+ break;
200
+ }
201
+ return _context3.abrupt("return", true);
202
+ case 1:
203
+ _context3.next = 2;
204
+ return value;
205
+ case 2:
206
+ return _context3.abrupt("return", false);
207
+ case 3:
208
+ case "end":
209
+ return _context3.stop();
210
+ }
211
+ }, recordValueMatch);
212
+ });
213
+ var recordValueMatchWith = function recordValueMatchWith(entity, value) {
214
+ var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : keyIndex + 1;
215
+ return /*#__PURE__*/_regenerator["default"].mark(function _callee() {
216
+ var matched;
217
+ return _regenerator["default"].wrap(function (_context4) {
218
+ while (1) switch (_context4.prev = _context4.next) {
219
+ case 0:
220
+ return _context4.delegateYield(recordValueMatch(entity, value), "t0", 1);
221
+ case 1:
222
+ matched = _context4.t0;
223
+ if (!matched) {
224
+ // 不管是不是使用 `keyIndex` 生成的 `key`,都自增一次,如果是,则可以保持一致
225
+ keyIndex++;
226
+ prevKeyIndex = key;
227
+ }
228
+ return _context4.abrupt("return", prevKeyIndex);
229
+ case 2:
230
+ case "end":
231
+ return _context4.stop();
232
+ }
233
+ }, _callee);
234
+ })();
235
+ };
236
+ return _objectSpread(_objectSpread({}, entityReducers), {}, {
237
+ isValueChanged: isValueChanged,
238
+ isValueMatched: isValueMatched,
239
+ matchProperty: matchProperty,
240
+ recordValue: recordValue,
241
+ recordValueDiff: recordValueDiff,
242
+ recordValueMatch: recordValueMatch,
243
+ recordValueMatchWith: recordValueMatchWith
244
+ });
245
+ };
246
+ });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mic-rexjs/usecases-react",
3
- "version": "2.10.2",
3
+ "version": "2.11.0",
4
4
  "description": "React-based solution for use usecases of Clean Architecture",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -35,50 +35,55 @@
35
35
  },
36
36
  "license": "MIT",
37
37
  "peerDependencies": {
38
- "@mic-rexjs/usecases": "^2.13.0",
39
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
38
+ "@mic-rexjs/usecases": "^2.14.2",
39
+ "react": ">=16.8.0"
40
40
  },
41
41
  "dependencies": {
42
- "@babel/plugin-transform-runtime": "^7.22.7",
43
- "@babel/preset-env": "^7.22.7",
44
- "ahooks": "^3.7.8"
42
+ "@babel/plugin-transform-runtime": "^7.29.0",
43
+ "@babel/preset-env": "^7.29.5",
44
+ "ahooks": "^3.9.7"
45
45
  },
46
46
  "devDependencies": {
47
- "@babel/cli": "^7.22.9",
48
- "@babel/core": "^7.22.8",
49
- "@babel/preset-react": "^7.22.5",
50
- "@babel/preset-typescript": "^7.22.5",
51
- "@commitlint/cli": "^19.0.3",
52
- "@commitlint/config-angular": "^19.0.3",
53
- "@jest/globals": "^29.5.0",
54
- "@mic-rexjs/usecases": "^2.13.0",
55
- "@testing-library/react": "^14.0.0",
56
- "@types/node": "^20.4.2",
57
- "@types/react": "^18.2.14",
58
- "@types/react-dom": "^18.2.7",
59
- "@typescript-eslint/eslint-plugin": "^7.1.1",
60
- "@typescript-eslint/parser": "^7.1.1",
61
- "babel-loader": "^9.1.3",
62
- "copy-webpack-plugin": "^12.0.2",
63
- "eslint": "^8.42.0",
64
- "eslint-config-prettier": "^9.1.0",
65
- "eslint-plugin-jest": "^27.2.1",
66
- "eslint-plugin-prettier": "^5.1.3",
67
- "eslint-plugin-react-hooks": "^4.6.0",
68
- "husky": "^9.0.11",
69
- "jest": "^29.5.0",
70
- "jest-environment-jsdom": "^29.6.1",
71
- "lint-staged": "^15.2.2",
72
- "prettier": "^3.2.5",
73
- "react": "^18.2.0",
74
- "react-dom": "^18.2.0",
75
- "rimraf": "^5.0.1",
76
- "ts-jest": "^29.1.0",
47
+ "@babel/cli": "^7.28.6",
48
+ "@babel/core": "^7.29.0",
49
+ "@babel/preset-react": "^7.28.5",
50
+ "@babel/preset-typescript": "^7.28.5",
51
+ "@commitlint/cli": "^20.5.3",
52
+ "@commitlint/config-angular": "^20.5.3",
53
+ "@eslint/eslintrc": "^3.3.5",
54
+ "@eslint/js": "^10.0.1",
55
+ "@ianvs/prettier-plugin-sort-imports": "^4.7.1",
56
+ "@jest/globals": "^30.3.0",
57
+ "@mic-rexjs/usecases": "^2.14.2",
58
+ "@testing-library/dom": "^10.4.1",
59
+ "@testing-library/react": "^16.3.2",
60
+ "@types/node": "^25.6.0",
61
+ "@types/react": "^19.2.14",
62
+ "@types/react-dom": "^19.2.3",
63
+ "@typescript-eslint/parser": "^8.59.2",
64
+ "babel-loader": "^10.1.1",
65
+ "copy-webpack-plugin": "^14.0.0",
66
+ "eslint": "^10.3.0",
67
+ "eslint-config-prettier": "^10.1.8",
68
+ "eslint-plugin-jest": "^29.15.2",
69
+ "eslint-plugin-prettier": "^5.5.5",
70
+ "eslint-plugin-react-hooks": "^7.1.1",
71
+ "globals": "^17.6.0",
72
+ "husky": "^9.1.7",
73
+ "jest": "^30.3.0",
74
+ "jest-environment-jsdom": "^30.3.0",
75
+ "lint-staged": "^17.0.2",
76
+ "prettier": "^3.8.3",
77
+ "react": "^19.2.6",
78
+ "react-dom": "^19.2.6",
79
+ "rimraf": "^6.1.3",
80
+ "ts-jest": "^29.4.9",
77
81
  "ts-node": "^10.9.1",
78
- "tsc-alias": "^1.8.7",
79
- "typescript": "^5.1.5",
80
- "webpack": "^5.74.0",
81
- "webpack-cli": "^5.1.4"
82
+ "tsc-alias": "^1.8.17",
83
+ "typescript": "^6.0.3",
84
+ "typescript-eslint": "^8.59.2",
85
+ "webpack": "^5.106.2",
86
+ "webpack-cli": "^7.0.2"
82
87
  },
83
88
  "lint-staged": {
84
89
  "./**/*.{js,ts,tsx}": "eslint"
@@ -1 +0,0 @@
1
- export declare const useCompareDeps: <T>(deps: T[]) => number;
@@ -1,11 +0,0 @@
1
- import { useRef } from 'react';
2
- import { isSameArray } from '../../methods/isSameArray';
3
- export const useCompareDeps = (deps) => {
4
- const updateTimesRef = useRef(0);
5
- const prevDepsRef = useRef([]);
6
- const { current: prevDeps } = prevDepsRef;
7
- const isSame = isSameArray(deps, prevDeps);
8
- prevDepsRef.current = deps;
9
- updateTimesRef.current += isSame ? 0 : 1;
10
- return updateTimesRef.current;
11
- };
@@ -1,2 +0,0 @@
1
- import { CacheableFactory, CacheCallOptions } from './types';
2
- export declare const cacheCall: <T extends CacheableFactory>(factory: T, options?: CacheCallOptions) => T;
@@ -1,26 +0,0 @@
1
- import { isSameArray } from '../isSameArray';
2
- export const cacheCall = (factory, options) => {
3
- let cache;
4
- const { onShouldCache = () => {
5
- return true;
6
- }, onCompare = (newArgs, oldArgs) => {
7
- return isSameArray(newArgs, oldArgs);
8
- }, } = options || {};
9
- return ((...args) => {
10
- const cacheable = onShouldCache();
11
- if (cache && cacheable) {
12
- const { parameters, returnValue } = cache;
13
- if (onCompare(parameters, args)) {
14
- return returnValue;
15
- }
16
- }
17
- const returnValue = factory(...args);
18
- if (cacheable) {
19
- cache = {
20
- parameters: args,
21
- returnValue,
22
- };
23
- }
24
- return returnValue;
25
- });
26
- };
@@ -1,13 +0,0 @@
1
- import { Reducer } from '@mic-rexjs/usecases';
2
- import { RestArguments } from '@mic-rexjs/usecases/es/types';
3
- export interface CacheableFactory {
4
- (...args: RestArguments): unknown;
5
- }
6
- export interface CacheCallOptions {
7
- onShouldCache?(): boolean;
8
- onCompare?(newArgs: RestArguments, oldArgs: RestArguments): boolean;
9
- }
10
- export interface CallCache<T extends Reducer> {
11
- parameters: Parameters<T>;
12
- returnValue: ReturnType<T>;
13
- }
@@ -1,2 +0,0 @@
1
- import { CacheCallOptions, CacheableFactory } from '../cacheCall/types';
2
- export declare const cacheCalls: <T extends Record<string, CacheableFactory>>(sourceFactories: T, options?: CacheCallOptions) => T;
@@ -1,8 +0,0 @@
1
- import { cacheCall } from '../cacheCall';
2
- export const cacheCalls = (sourceFactories, options) => {
3
- const cachedFactories = {};
4
- Object.entries(sourceFactories).forEach(([key, factory]) => {
5
- cachedFactories[key] = cacheCall(factory, options);
6
- });
7
- return cachedFactories;
8
- };
@@ -1,2 +0,0 @@
1
- import { CaptureCallFactory } from './types';
2
- export declare const captureCalls: <T extends object>(obj: T, callback: CaptureCallFactory) => T;
@@ -1,14 +0,0 @@
1
- export const captureCalls = (obj, callback) => {
2
- const newObj = {};
3
- Object.keys(obj).forEach((key) => {
4
- const value = obj[key];
5
- if (typeof value === 'function') {
6
- newObj[key] = ((...args) => {
7
- return callback(key, args);
8
- });
9
- return;
10
- }
11
- newObj[key] = value;
12
- });
13
- return newObj;
14
- };
@@ -1,4 +0,0 @@
1
- import { RestArguments } from '@mic-rexjs/usecases/es/types';
2
- export interface CaptureCallFactory {
3
- <T>(key: string, args: RestArguments): T;
4
- }
@@ -1,2 +0,0 @@
1
- import { ComparePropertyCallback } from './types';
2
- export declare const compareProperty: <T, S>(from: T, to: S, fieldPath: string, callback: ComparePropertyCallback, fieldPathStack?: string[]) => void;
@@ -1,34 +0,0 @@
1
- import { hasField } from '../hasField';
2
- export const compareProperty = (from, to, fieldPath, callback, fieldPathStack = []) => {
3
- const undef = void 0;
4
- const [, key = fieldPath, subFieldPath = ''] = fieldPath.match(/^([^.]+)\.(.+)$/) || [];
5
- const hasFromField = hasField(from, key);
6
- const hasToField = hasField(to, key);
7
- const currentFieldPathStack = [...fieldPathStack, key];
8
- if (hasFromField || hasToField) {
9
- const fromValue = hasFromField ? from[key] : undef;
10
- const toValue = hasToField ? to[key] : undef;
11
- if (subFieldPath) {
12
- compareProperty(fromValue, toValue, subFieldPath, callback, currentFieldPathStack);
13
- return;
14
- }
15
- if (fromValue === toValue) {
16
- return;
17
- }
18
- callback(fromValue, toValue, currentFieldPathStack);
19
- return;
20
- }
21
- if (/^\d+^/.test(key)) {
22
- return;
23
- }
24
- const fromArray = Array.isArray(from) ? from : [];
25
- const toArray = Array.isArray(to) ? to : [];
26
- const { length: fromLength } = fromArray;
27
- const { length: toLength } = toArray;
28
- const length = Math.max(fromLength, toLength);
29
- for (let i = 0; i < length; i++) {
30
- const fromItem = fromArray[i];
31
- const toItem = toArray[i];
32
- compareProperty(fromItem, toItem, fieldPath, callback, [...fieldPathStack, `${i}`]);
33
- }
34
- };
@@ -1,3 +0,0 @@
1
- export interface ComparePropertyCallback {
2
- <T, S>(fromValue: T, toValue: S, fieldPaths: string[]): void;
3
- }
@@ -1 +0,0 @@
1
- export declare const hasField: <T>(data: T, field: string) => boolean;
@@ -1,6 +0,0 @@
1
- export const hasField = (data, field) => {
2
- if (typeof data !== 'object' || data === null) {
3
- return false;
4
- }
5
- return Object.hasOwn(data, field);
6
- };
@@ -1,5 +0,0 @@
1
- import { EntityStore } from '@mic-rexjs/usecases';
2
- import { UseCaseHookOptions } from '../../hooks/useUseCase/types';
3
- import { ContextualEntityReducers } from '../../usecases/contextUseCase/types';
4
- import { EntityReducerMap, InferableEntityUseCase } from '@mic-rexjs/usecases/es/types';
5
- export declare const initEntityReducers: <T, TEntityReducers extends EntityReducerMap<T>, TUseCaseOptions extends object = object>(usecase: InferableEntityUseCase<T, TEntityReducers, TUseCaseOptions>, store: EntityStore<T>, options: UseCaseHookOptions<T, TUseCaseOptions>) => ContextualEntityReducers<T, TEntityReducers>;
@@ -1,11 +0,0 @@
1
- import { createEntityReducers } from '@mic-rexjs/usecases';
2
- export const initEntityReducers = (usecase, store, options) => {
3
- const { watch, onChange, options: usecaseOptions, ...restUseCaseOptions } = options;
4
- return createEntityReducers(store, usecase, {
5
- ...restUseCaseOptions,
6
- ...usecaseOptions,
7
- onGenerate(newEntity, result) {
8
- return result;
9
- },
10
- });
11
- };
@@ -1 +0,0 @@
1
- export declare const isSameArray: (array1: unknown[], array2: unknown[]) => boolean;