@mic-rexjs/usecases-react 2.10.1 → 2.10.3
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.min.js +1 -1
- package/dist/index.min.js.LICENSE.txt +4 -2
- package/es/components/SafeUseCaseFragment/index.js +1 -1
- package/es/components/UseCaseFragment/index.js +4 -3
- package/es/components/UseCaseFragment/types.d.ts +1 -1
- package/es/entities/matchPropertyFailedResult/types.d.ts +7 -0
- package/es/hooks/useArgumentTypes/index.d.ts +1 -1
- package/es/hooks/useArgumentTypes/index.js +3 -4
- package/es/hooks/useContext/index.d.ts +2 -2
- package/es/hooks/useContext/index.test.js +2 -2
- package/es/hooks/useContextualItem/index.d.ts +1 -1
- package/es/hooks/useContextualItem/index.js +15 -7
- package/es/hooks/useDepsKey/index.d.ts +2 -0
- package/es/hooks/useDepsKey/index.js +7 -0
- package/es/hooks/useEntity/index.d.ts +1 -1
- package/es/hooks/useEntity/index.js +6 -6
- package/es/hooks/useEntityReducers/index.d.ts +4 -0
- package/es/hooks/useEntityReducers/index.js +18 -0
- package/es/hooks/useFullArguments/index.d.ts +3 -3
- package/es/hooks/useFullArguments/types.d.ts +3 -2
- package/es/hooks/useIsRenderingRef/index.js +3 -3
- package/es/hooks/useProvider/index.d.ts +3 -3
- package/es/hooks/useProvider/index.js +3 -3
- package/es/hooks/useProvider/types.d.ts +0 -1
- package/es/hooks/useReducers/index.d.ts +4 -0
- package/es/hooks/useReducers/index.js +13 -0
- package/es/hooks/useRuntimeEntity/index.d.ts +1 -1
- package/es/hooks/useRuntimeEntity/index.js +6 -5
- package/es/hooks/useStatuses/index.d.ts +2 -2
- package/es/hooks/useStatuses/index.js +1 -1
- package/es/hooks/useUseCase/index.js +14 -13
- package/es/hooks/useUseCase/index.test.js +10 -6
- package/es/hooks/useUseCase/types.d.ts +11 -14
- package/es/methods/initEntityReducers/index.d.ts +2 -2
- package/es/methods/triggerWatchers/index.js +4 -9
- package/es/types.d.ts +3 -0
- package/es/usecases/contextUseCase/index.js +2 -2
- package/es/usecases/contextUseCase/types.d.ts +3 -4
- package/es/usecases/methodUseCase/index.d.ts +2 -0
- package/es/usecases/methodUseCase/index.js +55 -0
- package/es/usecases/methodUseCase/types.d.ts +21 -0
- package/es/usecases/valueUseCase/index.d.ts +2 -0
- package/es/usecases/valueUseCase/index.js +136 -0
- package/es/usecases/valueUseCase/types.d.ts +16 -0
- package/es/usecases/valueUseCase/types.js +1 -0
- package/lib/components/SafeUseCaseFragment/index.js +1 -1
- package/lib/components/UseCaseFragment/index.js +4 -3
- package/lib/hooks/useArgumentTypes/index.js +3 -4
- package/lib/hooks/useContext/index.test.js +2 -2
- package/lib/hooks/useContextualItem/index.js +15 -6
- package/lib/hooks/useDepsKey/index.js +18 -0
- package/lib/hooks/useEntity/index.js +6 -6
- package/lib/hooks/useEntityReducers/index.js +30 -0
- package/lib/hooks/useIsRenderingRef/index.js +2 -2
- package/lib/hooks/useProvider/index.js +4 -6
- package/lib/hooks/useReducers/index.js +20 -0
- package/lib/hooks/useRuntimeEntity/index.js +8 -5
- package/lib/hooks/useStatuses/index.js +1 -1
- package/lib/hooks/useUseCase/index.js +18 -15
- package/lib/hooks/useUseCase/index.test.js +222 -218
- package/lib/methods/triggerWatchers/index.js +5 -9
- package/lib/usecases/contextUseCase/index.js +2 -2
- package/lib/usecases/methodUseCase/index.js +79 -0
- package/lib/usecases/valueUseCase/index.js +198 -0
- package/lib/usecases/valueUseCase/types.js +5 -0
- package/package.json +45 -40
- package/es/hooks/useCompareDeps/index.d.ts +0 -1
- package/es/hooks/useCompareDeps/index.js +0 -11
- package/es/methods/cacheCall/index.d.ts +0 -2
- package/es/methods/cacheCall/index.js +0 -26
- package/es/methods/cacheCall/types.d.ts +0 -13
- package/es/methods/cacheCalls/index.d.ts +0 -2
- package/es/methods/cacheCalls/index.js +0 -8
- package/es/methods/captureCalls/index.d.ts +0 -2
- package/es/methods/captureCalls/index.js +0 -14
- package/es/methods/captureCalls/types.d.ts +0 -4
- package/es/methods/compareProperty/index.d.ts +0 -2
- package/es/methods/compareProperty/index.js +0 -34
- package/es/methods/compareProperty/types.d.ts +0 -3
- package/es/methods/hasField/index.d.ts +0 -1
- package/es/methods/hasField/index.js +0 -6
- package/es/methods/isSameArray/index.d.ts +0 -1
- package/es/methods/isSameArray/index.js +0 -14
- package/lib/hooks/useCompareDeps/index.js +0 -17
- package/lib/methods/cacheCall/index.js +0 -41
- package/lib/methods/cacheCalls/index.js +0 -19
- package/lib/methods/captureCalls/index.js +0 -23
- package/lib/methods/compareProperty/index.js +0 -49
- package/lib/methods/hasField/index.js +0 -14
- package/lib/methods/isSameArray/index.js +0 -20
- /package/es/{methods/cacheCall → entities/matchPropertyFailedResult}/types.js +0 -0
- /package/es/{methods/captureCalls/types.js → types.js} +0 -0
- /package/es/{methods/compareProperty → usecases/methodUseCase}/types.js +0 -0
- /package/lib/{methods/cacheCall → entities/matchPropertyFailedResult}/types.js +0 -0
- /package/lib/{methods/captureCalls/types.js → types.js} +0 -0
- /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
|
|
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
|
-
(
|
|
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();
|
|
@@ -27,7 +27,7 @@ var contextUseCase = exports.contextUseCase = (0, _usecases.createUseCase)(funct
|
|
|
27
27
|
};
|
|
28
28
|
var getUseCaseContext = function getUseCaseContext(usecase) {
|
|
29
29
|
if (!referenceMap.has(usecase)) {
|
|
30
|
-
return
|
|
30
|
+
return defaultUseCaseContext;
|
|
31
31
|
}
|
|
32
32
|
var _referenceMap$get = referenceMap.get(usecase),
|
|
33
33
|
value = _referenceMap$get.value;
|
|
@@ -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,198 @@
|
|
|
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) {
|
|
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 keys1 = Object.keys(entity);
|
|
40
|
+
var keys2 = Object.keys(value);
|
|
41
|
+
var length1 = keys1.length;
|
|
42
|
+
var length2 = keys2.length;
|
|
43
|
+
if (length1 !== length2) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
for (var _i = 0, _keys = keys1; _i < _keys.length; _i++) {
|
|
47
|
+
var key = _keys[_i];
|
|
48
|
+
var value1 = entity[key];
|
|
49
|
+
var value2 = value[key];
|
|
50
|
+
if (value1 === value2) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
};
|
|
57
|
+
var matchProperty = function matchProperty(entity, value, fieldPath, onFailed) {
|
|
58
|
+
var allMatched = true;
|
|
59
|
+
var currentFieldPath = fieldPath;
|
|
60
|
+
var list = [{
|
|
61
|
+
fieldPaths: [],
|
|
62
|
+
newEntity: value,
|
|
63
|
+
newValue: value,
|
|
64
|
+
oldEntity: entity,
|
|
65
|
+
oldValue: entity
|
|
66
|
+
}];
|
|
67
|
+
do {
|
|
68
|
+
var _list$shift = list.shift(),
|
|
69
|
+
oldValue = _list$shift.oldValue,
|
|
70
|
+
newValue = _list$shift.newValue,
|
|
71
|
+
fieldPaths = _list$shift.fieldPaths;
|
|
72
|
+
var _ref = currentFieldPath.match(/^([^.]+)\.(.+)$/) || [],
|
|
73
|
+
_ref2 = (0, _slicedToArray2["default"])(_ref, 3),
|
|
74
|
+
_ref2$ = _ref2[1],
|
|
75
|
+
key = _ref2$ === void 0 ? currentFieldPath : _ref2$,
|
|
76
|
+
_ref2$2 = _ref2[2],
|
|
77
|
+
subFieldPath = _ref2$2 === void 0 ? '' : _ref2$2;
|
|
78
|
+
var hasOldField = hasField(oldValue, key);
|
|
79
|
+
var hasNewField = hasField(newValue, key);
|
|
80
|
+
if (hasOldField || hasNewField) {
|
|
81
|
+
var subOldValue = hasOldField ? oldValue[key] : void 0;
|
|
82
|
+
var subNewValue = hasNewField ? newValue[key] : void 0;
|
|
83
|
+
var result = {
|
|
84
|
+
fieldPaths: [].concat((0, _toConsumableArray2["default"])(fieldPaths), [key]),
|
|
85
|
+
newEntity: value,
|
|
86
|
+
newValue: subNewValue,
|
|
87
|
+
oldEntity: entity,
|
|
88
|
+
oldValue: subOldValue
|
|
89
|
+
};
|
|
90
|
+
if (subFieldPath) {
|
|
91
|
+
currentFieldPath = subFieldPath;
|
|
92
|
+
list.push(result);
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (subOldValue === subNewValue) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
allMatched = false;
|
|
99
|
+
onFailed === null || onFailed === void 0 || onFailed(result);
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
if (/^\d+^/.test(key)) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
var oldArray = Array.isArray(oldValue) ? oldValue : [];
|
|
106
|
+
var newArray = Array.isArray(newValue) ? newValue : [];
|
|
107
|
+
var oldLength = oldArray.length;
|
|
108
|
+
var newLength = newArray.length;
|
|
109
|
+
var length = Math.max(oldLength, newLength);
|
|
110
|
+
for (var i = 0; i < length; i++) {
|
|
111
|
+
list.push({
|
|
112
|
+
fieldPaths: [].concat((0, _toConsumableArray2["default"])(fieldPaths), ["".concat(i)]),
|
|
113
|
+
newEntity: value,
|
|
114
|
+
newValue: newArray[i],
|
|
115
|
+
oldEntity: entity,
|
|
116
|
+
oldValue: oldArray[i]
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
} while (list.length > 0);
|
|
120
|
+
return allMatched;
|
|
121
|
+
};
|
|
122
|
+
var recordValue = /*#__PURE__*/_regenerator["default"].mark(function recordValue(entity, value) {
|
|
123
|
+
var changed;
|
|
124
|
+
return _regenerator["default"].wrap(function (_context) {
|
|
125
|
+
while (1) switch (_context.prev = _context.next) {
|
|
126
|
+
case 0:
|
|
127
|
+
changed = isValueChanged(entity, value);
|
|
128
|
+
if (changed) {
|
|
129
|
+
_context.next = 1;
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
return _context.abrupt("return", false);
|
|
133
|
+
case 1:
|
|
134
|
+
_context.next = 2;
|
|
135
|
+
return value;
|
|
136
|
+
case 2:
|
|
137
|
+
return _context.abrupt("return", true);
|
|
138
|
+
case 3:
|
|
139
|
+
case "end":
|
|
140
|
+
return _context.stop();
|
|
141
|
+
}
|
|
142
|
+
}, recordValue);
|
|
143
|
+
});
|
|
144
|
+
var recordValueMatch = /*#__PURE__*/_regenerator["default"].mark(function recordValueMatch(entity, value) {
|
|
145
|
+
var matched;
|
|
146
|
+
return _regenerator["default"].wrap(function (_context2) {
|
|
147
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
148
|
+
case 0:
|
|
149
|
+
matched = isValueMatched(entity, value);
|
|
150
|
+
if (!matched) {
|
|
151
|
+
_context2.next = 1;
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
return _context2.abrupt("return", true);
|
|
155
|
+
case 1:
|
|
156
|
+
_context2.next = 2;
|
|
157
|
+
return value;
|
|
158
|
+
case 2:
|
|
159
|
+
return _context2.abrupt("return", false);
|
|
160
|
+
case 3:
|
|
161
|
+
case "end":
|
|
162
|
+
return _context2.stop();
|
|
163
|
+
}
|
|
164
|
+
}, recordValueMatch);
|
|
165
|
+
});
|
|
166
|
+
var recordValueMatchWith = function recordValueMatchWith(entity, value) {
|
|
167
|
+
var key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : keyIndex + 1;
|
|
168
|
+
return /*#__PURE__*/_regenerator["default"].mark(function _callee() {
|
|
169
|
+
var matched;
|
|
170
|
+
return _regenerator["default"].wrap(function (_context3) {
|
|
171
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
172
|
+
case 0:
|
|
173
|
+
return _context3.delegateYield(recordValueMatch(entity, value), "t0", 1);
|
|
174
|
+
case 1:
|
|
175
|
+
matched = _context3.t0;
|
|
176
|
+
if (!matched) {
|
|
177
|
+
// 不管是不是使用 `keyIndex` 生成的 `key`,都自增一次,如果是,则可以保持一致
|
|
178
|
+
keyIndex++;
|
|
179
|
+
prevKeyIndex = key;
|
|
180
|
+
}
|
|
181
|
+
return _context3.abrupt("return", prevKeyIndex);
|
|
182
|
+
case 2:
|
|
183
|
+
case "end":
|
|
184
|
+
return _context3.stop();
|
|
185
|
+
}
|
|
186
|
+
}, _callee);
|
|
187
|
+
})();
|
|
188
|
+
};
|
|
189
|
+
return _objectSpread(_objectSpread({}, entityReducers), {}, {
|
|
190
|
+
isValueChanged: isValueChanged,
|
|
191
|
+
isValueMatched: isValueMatched,
|
|
192
|
+
matchProperty: matchProperty,
|
|
193
|
+
recordValue: recordValue,
|
|
194
|
+
recordValueMatch: recordValueMatch,
|
|
195
|
+
recordValueMatchWith: recordValueMatchWith
|
|
196
|
+
});
|
|
197
|
+
};
|
|
198
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mic-rexjs/usecases-react",
|
|
3
|
-
"version": "2.10.
|
|
3
|
+
"version": "2.10.3",
|
|
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.
|
|
39
|
-
"react": "
|
|
38
|
+
"@mic-rexjs/usecases": "^2.14.2",
|
|
39
|
+
"react": ">=16.8.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@babel/plugin-transform-runtime": "^7.
|
|
43
|
-
"@babel/preset-env": "^7.
|
|
44
|
-
"ahooks": "^3.7
|
|
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.
|
|
48
|
-
"@babel/core": "^7.
|
|
49
|
-
"@babel/preset-react": "^7.
|
|
50
|
-
"@babel/preset-typescript": "^7.
|
|
51
|
-
"@commitlint/cli": "^
|
|
52
|
-
"@commitlint/config-angular": "^
|
|
53
|
-
"@
|
|
54
|
-
"@
|
|
55
|
-
"@
|
|
56
|
-
"@
|
|
57
|
-
"@
|
|
58
|
-
"@
|
|
59
|
-
"@
|
|
60
|
-
"@
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"eslint": "^8.
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"eslint
|
|
67
|
-
"eslint-
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
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.
|
|
79
|
-
"typescript": "^
|
|
80
|
-
"
|
|
81
|
-
"webpack
|
|
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,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,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,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,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 +0,0 @@
|
|
|
1
|
-
export declare const hasField: <T>(data: T, field: string) => boolean;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const isSameArray: (array1: unknown[], array2: unknown[]) => boolean;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
export const isSameArray = (array1, array2) => {
|
|
2
|
-
const { length: length1 } = array1;
|
|
3
|
-
const { length: length2 } = array2;
|
|
4
|
-
if (length1 !== length2) {
|
|
5
|
-
return false;
|
|
6
|
-
}
|
|
7
|
-
for (let i = 0; i < length1; i++) {
|
|
8
|
-
if (array1[i] === array2[i]) {
|
|
9
|
-
continue;
|
|
10
|
-
}
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
return true;
|
|
14
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useCompareDeps = void 0;
|
|
7
|
-
var _react = require("react");
|
|
8
|
-
var _isSameArray = require("../../methods/isSameArray");
|
|
9
|
-
var useCompareDeps = exports.useCompareDeps = function useCompareDeps(deps) {
|
|
10
|
-
var updateTimesRef = (0, _react.useRef)(0);
|
|
11
|
-
var prevDepsRef = (0, _react.useRef)([]);
|
|
12
|
-
var prevDeps = prevDepsRef.current;
|
|
13
|
-
var isSame = (0, _isSameArray.isSameArray)(deps, prevDeps);
|
|
14
|
-
prevDepsRef.current = deps;
|
|
15
|
-
updateTimesRef.current += isSame ? 0 : 1;
|
|
16
|
-
return updateTimesRef.current;
|
|
17
|
-
};
|