@mic-rexjs/usecases-react 2.11.2 → 2.12.1
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/es/components/SafeUseCaseFragment/index.js +17 -7
- package/es/components/SafeUseCaseFragment/types.js +1 -1
- package/es/components/UseCaseFragment/index.js +16 -6
- package/es/components/UseCaseFragment/types.js +1 -1
- package/es/entities/matchPropertyFailedResult/types.js +1 -1
- package/es/enums/ArgumentTypes/index.js +3 -3
- package/es/enums/Statuses/index.js +22 -22
- package/es/hooks/useArgumentTypes/index.js +12 -10
- package/es/hooks/useConstant/index.js +7 -4
- package/es/hooks/useConstant/types.js +1 -1
- package/es/hooks/useConstantEntityReducers/index.js +4 -4
- package/es/hooks/useConstantFn/index.js +9 -6
- package/es/hooks/useConstantReducers/index.js +4 -4
- package/es/hooks/useContext/index.js +14 -11
- package/es/hooks/useContext/index.test.js +50 -44
- package/es/hooks/useContextualItem/index.js +27 -25
- package/es/hooks/useContextualItem/types.js +1 -1
- package/es/hooks/useDepsKey/index.js +9 -5
- package/es/hooks/useEntity/index.js +65 -61
- package/es/hooks/useFullArguments/index.js +12 -17
- package/es/hooks/useFullArguments/types.js +1 -1
- package/es/hooks/useIsRenderingRef/index.js +6 -6
- package/es/hooks/useProvider/index.js +21 -15
- package/es/hooks/useProvider/types.js +1 -1
- package/es/hooks/useRuntimeEntity/index.js +18 -16
- package/es/hooks/useStatuses/index.js +19 -19
- package/es/hooks/useUseCase/index.js +78 -57
- package/es/hooks/useUseCase/index.test.js +2402 -1701
- package/es/hooks/useUseCase/types.d.ts +11 -8
- package/es/hooks/useUseCase/types.js +1 -1
- package/es/index.js +1 -1
- package/es/methods/triggerWatchers/index.js +12 -7
- package/es/types.js +1 -1
- package/es/usecases/contextUseCase/index.js +70 -65
- package/es/usecases/contextUseCase/types.js +1 -1
- package/es/usecases/methodUseCase/index.js +69 -52
- package/es/usecases/methodUseCase/types.js +1 -1
- package/es/usecases/valueUseCase/index.js +175 -167
- package/es/usecases/valueUseCase/types.js +1 -1
- package/lib/components/UseCaseFragment/index.js +1 -1
- package/lib/hooks/useUseCase/index.js +5 -8
- package/lib/hooks/useUseCase/index.test.js +198 -104
- package/lib/methods/triggerWatchers/index.js +9 -7
- package/lib/usecases/valueUseCase/index.js +1 -1
- package/package.json +3 -3
|
@@ -1,170 +1,178 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
2
|
import { createUseCase, entityUseCase, utilsUseCase } from '@mic-rexjs/usecases';
|
|
2
3
|
export const valueUseCase = createUseCase(() => {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const isValueChanged = (entity, value) => {
|
|
14
|
-
return entity !== value;
|
|
15
|
-
};
|
|
16
|
-
const isValueMatched = (entity, value, onMatchFailed) => {
|
|
17
|
-
if (entity === value) {
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
const isObject1 = typeof entity === 'object' && entity !== null;
|
|
21
|
-
const isObject2 = typeof value === 'object' && value !== null;
|
|
22
|
-
if (!isObject1 || !isObject2) {
|
|
23
|
-
return false;
|
|
24
|
-
}
|
|
25
|
-
let allMatched = true;
|
|
26
|
-
const keys1 = Object.keys(entity);
|
|
27
|
-
const keys2 = Object.keys(value);
|
|
28
|
-
const { length: length1 } = keys1;
|
|
29
|
-
const keys = [...keys1, ...keys2];
|
|
30
|
-
const hasCallback = typeof onMatchFailed === 'function';
|
|
31
|
-
for (let i = 0, { length } = keys; i < length; i++) {
|
|
32
|
-
const key = keys[i];
|
|
33
|
-
const isFromKeys2 = i >= length1;
|
|
34
|
-
const isInKey1 = keys1.includes(key);
|
|
35
|
-
const isUsed = isFromKeys2 && isInKey1;
|
|
36
|
-
if (isUsed) {
|
|
37
|
-
continue;
|
|
38
|
-
}
|
|
39
|
-
const hasField1 = Object.hasOwn(entity, key);
|
|
40
|
-
const hasField2 = Object.hasOwn(value, key);
|
|
41
|
-
const onlyHasField1 = hasField1 && !hasField2;
|
|
42
|
-
const onlyHasField2 = !hasField1 && hasField2;
|
|
43
|
-
const onlyHasOneField = onlyHasField1 || onlyHasField2;
|
|
44
|
-
const value1 = entity[key];
|
|
45
|
-
const value2 = value[key];
|
|
46
|
-
const matched = value1 === value2;
|
|
47
|
-
if (!onlyHasOneField && matched) {
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
allMatched = false;
|
|
51
|
-
if (hasCallback) {
|
|
52
|
-
onMatchFailed(key, value2, value1);
|
|
53
|
-
continue;
|
|
54
|
-
}
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
return allMatched;
|
|
58
|
-
};
|
|
59
|
-
const matchProperty = (entity, value, fieldPath, onFailed) => {
|
|
60
|
-
let allMatched = true;
|
|
61
|
-
let currentFieldPath = fieldPath;
|
|
62
|
-
const list = [
|
|
63
|
-
{
|
|
64
|
-
fieldPaths: [],
|
|
65
|
-
newEntity: value,
|
|
66
|
-
newValue: value,
|
|
67
|
-
oldEntity: entity,
|
|
68
|
-
oldValue: entity,
|
|
69
|
-
},
|
|
70
|
-
];
|
|
71
|
-
do {
|
|
72
|
-
const { oldValue, newValue, fieldPaths } = list.shift();
|
|
73
|
-
const [, key = currentFieldPath, subFieldPath = ''] = currentFieldPath.match(/^([^.]+)\.(.+)$/) || [];
|
|
74
|
-
const hasOldField = hasField(oldValue, key);
|
|
75
|
-
const hasNewField = hasField(newValue, key);
|
|
76
|
-
if (hasOldField || hasNewField) {
|
|
77
|
-
const subOldValue = hasOldField ? oldValue[key] : void 0;
|
|
78
|
-
const subNewValue = hasNewField ? newValue[key] : void 0;
|
|
79
|
-
const result = {
|
|
80
|
-
fieldPaths: [...fieldPaths, key],
|
|
81
|
-
newEntity: value,
|
|
82
|
-
newValue: subNewValue,
|
|
83
|
-
oldEntity: entity,
|
|
84
|
-
oldValue: subOldValue,
|
|
85
|
-
};
|
|
86
|
-
if (subFieldPath) {
|
|
87
|
-
currentFieldPath = subFieldPath;
|
|
88
|
-
list.push(result);
|
|
89
|
-
continue;
|
|
90
|
-
}
|
|
91
|
-
if (subOldValue === subNewValue) {
|
|
92
|
-
continue;
|
|
93
|
-
}
|
|
94
|
-
allMatched = false;
|
|
95
|
-
onFailed?.(result);
|
|
96
|
-
continue;
|
|
97
|
-
}
|
|
98
|
-
if (/^\d+^/.test(key)) {
|
|
99
|
-
continue;
|
|
100
|
-
}
|
|
101
|
-
const oldArray = Array.isArray(oldValue) ? oldValue : [];
|
|
102
|
-
const newArray = Array.isArray(newValue) ? newValue : [];
|
|
103
|
-
const { length: oldLength } = oldArray;
|
|
104
|
-
const { length: newLength } = newArray;
|
|
105
|
-
const length = Math.max(oldLength, newLength);
|
|
106
|
-
for (let i = 0; i < length; i++) {
|
|
107
|
-
list.push({
|
|
108
|
-
fieldPaths: [...fieldPaths, `${i}`],
|
|
109
|
-
newEntity: value,
|
|
110
|
-
newValue: newArray[i],
|
|
111
|
-
oldEntity: entity,
|
|
112
|
-
oldValue: oldArray[i],
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
} while (list.length > 0);
|
|
116
|
-
return allMatched;
|
|
117
|
-
};
|
|
118
|
-
const recordValue = function* (entity, value) {
|
|
119
|
-
const changed = isValueChanged(entity, value);
|
|
120
|
-
if (!changed) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
yield value;
|
|
124
|
-
return true;
|
|
125
|
-
};
|
|
126
|
-
const recordValueDiff = function* (entity, value) {
|
|
127
|
-
const isArray1 = Array.isArray(entity);
|
|
128
|
-
const isArray2 = Array.isArray(value);
|
|
129
|
-
const isArray = isArray1 && isArray2;
|
|
130
|
-
const result = (isArray ? [] : {});
|
|
131
|
-
if (isArray) {
|
|
132
|
-
const { length: length1 } = entity;
|
|
133
|
-
const { length: length2 } = value;
|
|
134
|
-
result.length = Math.max(length1, length2);
|
|
135
|
-
}
|
|
136
|
-
const matched = isValueMatched(entity, value, (key, newValue) => {
|
|
137
|
-
result[key] = newValue;
|
|
138
|
-
});
|
|
139
|
-
if (!matched) {
|
|
140
|
-
yield value;
|
|
141
|
-
}
|
|
142
|
-
return result;
|
|
143
|
-
};
|
|
144
|
-
const recordValueMatch = function* (entity, value) {
|
|
145
|
-
const matched = isValueMatched(entity, value);
|
|
146
|
-
if (matched) {
|
|
147
|
-
return true;
|
|
148
|
-
}
|
|
149
|
-
yield value;
|
|
150
|
-
return false;
|
|
151
|
-
};
|
|
152
|
-
const recordValueMatchWith = function* (entity, value, key) {
|
|
153
|
-
const matched = yield* recordValueMatch(entity, value);
|
|
154
|
-
if (!matched) {
|
|
155
|
-
prevKeyIndex = key ?? createKey();
|
|
156
|
-
}
|
|
157
|
-
return prevKeyIndex;
|
|
158
|
-
};
|
|
159
|
-
return {
|
|
160
|
-
...entityReducers,
|
|
161
|
-
isValueChanged,
|
|
162
|
-
isValueMatched,
|
|
163
|
-
matchProperty,
|
|
164
|
-
recordValue,
|
|
165
|
-
recordValueDiff,
|
|
166
|
-
recordValueMatch,
|
|
167
|
-
recordValueMatchWith,
|
|
168
|
-
};
|
|
4
|
+
return () => {
|
|
5
|
+
const _utilsUseCase = utilsUseCase(),
|
|
6
|
+
createKey = _utilsUseCase.createKey;
|
|
7
|
+
let prevKeyIndex = createKey();
|
|
8
|
+
const entityReducers = entityUseCase();
|
|
9
|
+
const hasField = (entity, field) => {
|
|
10
|
+
if (typeof entity !== 'object' || entity === null) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
return Object.hasOwn(entity, field);
|
|
169
14
|
};
|
|
170
|
-
|
|
15
|
+
const isValueChanged = (entity, value) => {
|
|
16
|
+
return entity !== value;
|
|
17
|
+
};
|
|
18
|
+
const isValueMatched = (entity, value, onMatchFailed) => {
|
|
19
|
+
if (entity === value) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
const isObject1 = typeof entity === 'object' && entity !== null;
|
|
23
|
+
const isObject2 = typeof value === 'object' && value !== null;
|
|
24
|
+
if (!isObject1 || !isObject2) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
let allMatched = true;
|
|
28
|
+
const keys1 = Object.keys(entity);
|
|
29
|
+
const keys2 = Object.keys(value);
|
|
30
|
+
const length1 = keys1.length;
|
|
31
|
+
const keys = [...keys1, ...keys2];
|
|
32
|
+
const hasCallback = typeof onMatchFailed === 'function';
|
|
33
|
+
for (let i = 0, length = keys.length; i < length; i++) {
|
|
34
|
+
const key = keys[i];
|
|
35
|
+
const isFromKeys2 = i >= length1;
|
|
36
|
+
const isInKey1 = keys1.includes(key);
|
|
37
|
+
const isUsed = isFromKeys2 && isInKey1;
|
|
38
|
+
if (isUsed) {
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const hasField1 = Object.hasOwn(entity, key);
|
|
42
|
+
const hasField2 = Object.hasOwn(value, key);
|
|
43
|
+
const onlyHasField1 = hasField1 && !hasField2;
|
|
44
|
+
const onlyHasField2 = !hasField1 && hasField2;
|
|
45
|
+
const onlyHasOneField = onlyHasField1 || onlyHasField2;
|
|
46
|
+
const value1 = entity[key];
|
|
47
|
+
const value2 = value[key];
|
|
48
|
+
const matched = value1 === value2;
|
|
49
|
+
if (!onlyHasOneField && matched) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
allMatched = false;
|
|
53
|
+
if (hasCallback) {
|
|
54
|
+
onMatchFailed(key, value2, value1);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
return allMatched;
|
|
60
|
+
};
|
|
61
|
+
const matchProperty = (entity, value, fieldPath, onFailed) => {
|
|
62
|
+
let allMatched = true;
|
|
63
|
+
let currentFieldPath = fieldPath;
|
|
64
|
+
const list = [{
|
|
65
|
+
fieldPaths: [],
|
|
66
|
+
newEntity: value,
|
|
67
|
+
newValue: value,
|
|
68
|
+
oldEntity: entity,
|
|
69
|
+
oldValue: entity
|
|
70
|
+
}];
|
|
71
|
+
do {
|
|
72
|
+
const _list$shift = list.shift(),
|
|
73
|
+
oldValue = _list$shift.oldValue,
|
|
74
|
+
newValue = _list$shift.newValue,
|
|
75
|
+
fieldPaths = _list$shift.fieldPaths;
|
|
76
|
+
const _ref = currentFieldPath.match(/^([^.]+)\.(.+)$/) || [],
|
|
77
|
+
_ref2 = _slicedToArray(_ref, 3),
|
|
78
|
+
_ref2$ = _ref2[1],
|
|
79
|
+
key = _ref2$ === void 0 ? currentFieldPath : _ref2$,
|
|
80
|
+
_ref2$2 = _ref2[2],
|
|
81
|
+
subFieldPath = _ref2$2 === void 0 ? '' : _ref2$2;
|
|
82
|
+
const hasOldField = hasField(oldValue, key);
|
|
83
|
+
const hasNewField = hasField(newValue, key);
|
|
84
|
+
if (hasOldField || hasNewField) {
|
|
85
|
+
const subOldValue = hasOldField ? oldValue[key] : void 0;
|
|
86
|
+
const subNewValue = hasNewField ? newValue[key] : void 0;
|
|
87
|
+
const result = {
|
|
88
|
+
fieldPaths: [...fieldPaths, key],
|
|
89
|
+
newEntity: value,
|
|
90
|
+
newValue: subNewValue,
|
|
91
|
+
oldEntity: entity,
|
|
92
|
+
oldValue: subOldValue
|
|
93
|
+
};
|
|
94
|
+
if (subFieldPath) {
|
|
95
|
+
currentFieldPath = subFieldPath;
|
|
96
|
+
list.push(result);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (subOldValue === subNewValue) {
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
allMatched = false;
|
|
103
|
+
onFailed === null || onFailed === void 0 || onFailed(result);
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (/^\d+^/.test(key)) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
const oldArray = Array.isArray(oldValue) ? oldValue : [];
|
|
110
|
+
const newArray = Array.isArray(newValue) ? newValue : [];
|
|
111
|
+
const oldLength = oldArray.length;
|
|
112
|
+
const newLength = newArray.length;
|
|
113
|
+
const length = Math.max(oldLength, newLength);
|
|
114
|
+
for (let i = 0; i < length; i++) {
|
|
115
|
+
list.push({
|
|
116
|
+
fieldPaths: [...fieldPaths, `${i}`],
|
|
117
|
+
newEntity: value,
|
|
118
|
+
newValue: newArray[i],
|
|
119
|
+
oldEntity: entity,
|
|
120
|
+
oldValue: oldArray[i]
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
} while (list.length > 0);
|
|
124
|
+
return allMatched;
|
|
125
|
+
};
|
|
126
|
+
const recordValue = function* (entity, value) {
|
|
127
|
+
const changed = isValueChanged(entity, value);
|
|
128
|
+
if (!changed) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
yield value;
|
|
132
|
+
return true;
|
|
133
|
+
};
|
|
134
|
+
const recordValueDiff = function* (entity, value) {
|
|
135
|
+
const isArray1 = Array.isArray(entity);
|
|
136
|
+
const isArray2 = Array.isArray(value);
|
|
137
|
+
const isArray = isArray1 && isArray2;
|
|
138
|
+
const result = isArray ? [] : {};
|
|
139
|
+
if (isArray) {
|
|
140
|
+
const length1 = entity.length;
|
|
141
|
+
const length2 = value.length;
|
|
142
|
+
result.length = Math.max(length1, length2);
|
|
143
|
+
}
|
|
144
|
+
const matched = isValueMatched(entity, value, (key, newValue) => {
|
|
145
|
+
result[key] = newValue;
|
|
146
|
+
});
|
|
147
|
+
if (!matched) {
|
|
148
|
+
yield value;
|
|
149
|
+
}
|
|
150
|
+
return result;
|
|
151
|
+
};
|
|
152
|
+
const recordValueMatch = function* (entity, value) {
|
|
153
|
+
const matched = isValueMatched(entity, value);
|
|
154
|
+
if (matched) {
|
|
155
|
+
return true;
|
|
156
|
+
}
|
|
157
|
+
yield value;
|
|
158
|
+
return false;
|
|
159
|
+
};
|
|
160
|
+
const recordValueMatchWith = function* (entity, value, key) {
|
|
161
|
+
const matched = yield* recordValueMatch(entity, value);
|
|
162
|
+
if (!matched) {
|
|
163
|
+
prevKeyIndex = key !== null && key !== void 0 ? key : createKey();
|
|
164
|
+
}
|
|
165
|
+
return prevKeyIndex;
|
|
166
|
+
};
|
|
167
|
+
return {
|
|
168
|
+
...entityReducers,
|
|
169
|
+
isValueChanged,
|
|
170
|
+
isValueMatched,
|
|
171
|
+
matchProperty,
|
|
172
|
+
recordValue,
|
|
173
|
+
recordValueDiff,
|
|
174
|
+
recordValueMatch,
|
|
175
|
+
recordValueMatchWith
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {};
|
|
1
|
+
export {};
|
|
@@ -12,9 +12,9 @@ var _useUseCase2 = require("../../hooks/useUseCase");
|
|
|
12
12
|
var _SafeUseCaseFragment = require("../SafeUseCaseFragment");
|
|
13
13
|
var _react = require("react");
|
|
14
14
|
var _contextUseCase = require("../../usecases/contextUseCase");
|
|
15
|
-
var _excluded = ["usecase"];
|
|
16
15
|
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; }
|
|
17
16
|
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; }
|
|
17
|
+
var _excluded = ["usecase"];
|
|
18
18
|
var UseCaseFragment = exports.UseCaseFragment = function UseCaseFragment(_ref) {
|
|
19
19
|
var usecase = _ref.usecase,
|
|
20
20
|
props = (0, _objectWithoutProperties2["default"])(_ref, _excluded);
|
|
@@ -7,8 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
exports.useUseCase = void 0;
|
|
8
8
|
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
-
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
12
12
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
13
13
|
var _useArgumentTypes = require("../useArgumentTypes");
|
|
14
14
|
var _useConstantFn = require("../useConstantFn");
|
|
@@ -25,9 +25,9 @@ var _ahooks = require("ahooks");
|
|
|
25
25
|
var _react = require("react");
|
|
26
26
|
var _Statuses = require("../../enums/Statuses");
|
|
27
27
|
var _methodUseCase = require("../../usecases/methodUseCase");
|
|
28
|
-
var _excluded = ["watch", "onChange", "options"];
|
|
29
28
|
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; }
|
|
30
29
|
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; }
|
|
30
|
+
var _excluded = ["watch", "onChange", "options"];
|
|
31
31
|
var useUseCase = exports.useUseCase = function useUseCase() {
|
|
32
32
|
var isRenderingRef = (0, _useIsRenderingRef.useIsRenderingRef)();
|
|
33
33
|
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
@@ -63,8 +63,9 @@ var useUseCase = exports.useUseCase = function useUseCase() {
|
|
|
63
63
|
captureCalls = _useConstantReducers.captureCalls;
|
|
64
64
|
var reducers = (0, _useContextualItem.useContextualItem)(contextReducers, statuses, function () {
|
|
65
65
|
var opts = captureCalls(options, function (key, callArgs) {
|
|
66
|
+
var _optionsRef$current$k2;
|
|
66
67
|
var _optionsRef$current$k, _optionsRef$current;
|
|
67
|
-
return (_optionsRef$current$k = (_optionsRef$current = optionsRef.current)[key]) === null || _optionsRef$current$k === void 0 ? void 0 : _optionsRef$current$k.call.apply(_optionsRef$current$
|
|
68
|
+
return (_optionsRef$current$k = (_optionsRef$current = optionsRef.current)[key]) === null || _optionsRef$current$k === void 0 ? void 0 : (_optionsRef$current$k2 = _optionsRef$current$k).call.apply(_optionsRef$current$k2, [_optionsRef$current].concat((0, _toConsumableArray2["default"])(callArgs)));
|
|
68
69
|
});
|
|
69
70
|
if ((statuses & _Statuses.Statuses.EntityEnabled) !== _Statuses.Statuses.EntityEnabled) {
|
|
70
71
|
return usecase(opts);
|
|
@@ -85,7 +86,6 @@ var useUseCase = exports.useUseCase = function useUseCase() {
|
|
|
85
86
|
if ((statuses & _Statuses.Statuses.EntityEnabled) !== _Statuses.Statuses.EntityEnabled) {
|
|
86
87
|
return reducers;
|
|
87
88
|
}
|
|
88
|
-
var rootEnabled = (statuses & _Statuses.Statuses.RootEnabled) === _Statuses.Statuses.RootEnabled;
|
|
89
89
|
var cachedReducers = cacheCalls(reducers, {
|
|
90
90
|
onShouldCache: function onShouldCache() {
|
|
91
91
|
return isRenderingRef.current;
|
|
@@ -97,9 +97,6 @@ var useUseCase = exports.useUseCase = function useUseCase() {
|
|
|
97
97
|
var isObjectEntity = isObjectType && !isNull && !isArray;
|
|
98
98
|
// 这里是为了让访问器 `getter` 的值保持唯一性,否则每次 `getter` 返回的对象都是新对象,无法用于 `deps`
|
|
99
99
|
var newEntity = isObjectEntity ? _objectSpread({}, entity) : entity;
|
|
100
|
-
|
|
101
|
-
return [newEntity, cachedReducers, Provider];
|
|
102
|
-
}
|
|
103
|
-
return [newEntity, cachedReducers];
|
|
100
|
+
return [newEntity, cachedReducers, Provider];
|
|
104
101
|
}, [statuses, entity, reducers, Provider, isRenderingRef, cacheCalls]);
|
|
105
102
|
};
|