@mic-rexjs/usecases-react 3.7.0 → 4.0.0-beta.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 +2 -0
- package/es/components/UseCaseFragment/index.js +2 -2
- package/es/enums/Statuses/index.d.ts +86 -10
- package/es/enums/Statuses/index.js +86 -10
- package/es/hooks/useAlternateStatuses/index.d.ts +2 -0
- package/es/hooks/useAlternateStatuses/index.js +16 -0
- package/es/hooks/useChanged/index.d.ts +2 -0
- package/es/hooks/useChanged/index.js +17 -0
- package/es/hooks/useChanged/types.d.ts +3 -0
- package/es/hooks/useContext/index.d.ts +3 -4
- package/es/hooks/useContext/index.js +17 -15
- package/es/hooks/useContext/index.test.js +13 -24
- package/es/hooks/useContextValue/index.d.ts +5 -0
- package/es/hooks/useContextValue/index.js +13 -0
- package/es/hooks/useDepsKey/index.js +11 -9
- package/es/hooks/useEntity/index.d.ts +3 -2
- package/es/hooks/useEntity/index.js +52 -53
- package/es/hooks/useEntityReturn/index.d.ts +5 -0
- package/es/hooks/useEntityReturn/index.js +15 -0
- package/es/hooks/useEntityReturn/types.d.ts +7 -0
- package/es/hooks/useEntityRootExec/index.d.ts +5 -0
- package/es/hooks/useEntityRootExec/index.js +7 -0
- package/es/hooks/useEntityRootExec/types.d.ts +7 -0
- package/es/hooks/useEntityRootExec/types.js +1 -0
- package/es/hooks/useEntityRootReturn/index.d.ts +5 -0
- package/es/hooks/useEntityRootReturn/index.js +14 -0
- package/es/hooks/useEntityRootReturn/types.d.ts +7 -0
- package/es/hooks/useEntityRootReturn/types.js +1 -0
- package/es/hooks/useExec/index.d.ts +2 -3
- package/es/hooks/useExec/index.js +3 -12
- package/es/hooks/useExec/types.d.ts +10 -2
- package/es/hooks/useFullArguments/index.d.ts +2 -3
- package/es/hooks/useFullArguments/index.js +4 -6
- package/es/hooks/useFullArguments/types.d.ts +2 -2
- package/es/hooks/useIfExec/index.d.ts +2 -0
- package/es/hooks/useIfExec/index.js +20 -0
- package/es/hooks/useIfExec/types.d.ts +6 -0
- package/es/hooks/useIfExec/types.js +1 -0
- package/es/hooks/useIfReturn/index.d.ts +2 -0
- package/es/hooks/useIfReturn/index.js +22 -0
- package/es/hooks/useIfReturn/types.d.ts +6 -0
- package/es/hooks/useIfReturn/types.js +1 -0
- package/es/hooks/useProvider/index.d.ts +3 -5
- package/es/hooks/useProvider/index.js +17 -23
- package/es/hooks/useProviders/index.js +4 -4
- package/es/hooks/useReducers/index.d.ts +5 -4
- package/es/hooks/useReducers/index.js +45 -27
- package/es/hooks/useReturn/index.d.ts +2 -0
- package/es/hooks/useReturn/index.js +33 -0
- package/es/hooks/useReturn/types.d.ts +11 -0
- package/es/hooks/useReturn/types.js +1 -0
- package/es/hooks/useRootInitializing/index.d.ts +2 -0
- package/es/hooks/useRootInitializing/index.js +14 -0
- package/es/hooks/useRootReturn/index.d.ts +5 -0
- package/es/hooks/useRootReturn/index.js +22 -0
- package/es/hooks/useRootReturn/types.d.ts +14 -0
- package/es/hooks/useRootReturn/types.js +1 -0
- package/es/hooks/useStatuses/index.d.ts +4 -4
- package/es/hooks/useStatuses/index.js +46 -21
- package/es/hooks/useStore/index.d.ts +3 -3
- package/es/hooks/useStore/index.js +21 -49
- package/es/hooks/useThrottleUpdate/index.d.ts +2 -0
- package/es/hooks/useThrottleUpdate/index.js +31 -0
- package/es/hooks/useThrottleUpdate/types.d.ts +3 -0
- package/es/hooks/useThrottleUpdate/types.js +1 -0
- package/es/hooks/useUseCase/index.js +21 -24
- package/es/hooks/useUseCase/index.test.js +330 -98
- package/es/hooks/useUseCase/types.d.ts +15 -5
- package/es/methods/cacheCall/index.d.ts +2 -0
- package/es/methods/cacheCall/index.js +38 -0
- package/es/methods/cacheCall/types.d.ts +12 -0
- package/es/methods/cacheCall/types.js +1 -0
- package/es/methods/cacheCalls/index.d.ts +2 -0
- package/es/methods/cacheCalls/index.js +12 -0
- package/es/types.d.ts +2 -1
- package/es/usecases/contextUseCase/index.js +21 -38
- package/es/usecases/contextUseCase/types.d.ts +5 -6
- package/es/usecases/lifecycleEventUseCase/index.js +37 -9
- package/es/usecases/lifecycleEventUseCase/types.d.ts +11 -8
- package/lib/components/UseCaseFragment/index.js +2 -2
- package/lib/enums/Statuses/index.js +86 -10
- package/lib/hooks/useAlternateStatuses/index.js +22 -0
- package/lib/hooks/useChanged/index.js +23 -0
- package/lib/hooks/useContext/index.js +19 -17
- package/lib/hooks/useContext/index.test.js +13 -24
- package/lib/hooks/useContextValue/index.js +19 -0
- package/lib/hooks/useDepsKey/index.js +10 -8
- package/lib/hooks/useEntity/index.js +81 -54
- package/lib/hooks/useEntityReturn/index.js +22 -0
- package/lib/hooks/useEntityRootExec/index.js +13 -0
- package/lib/hooks/useEntityRootExec/types.js +5 -0
- package/lib/hooks/useEntityRootReturn/index.js +21 -0
- package/lib/hooks/useEntityRootReturn/types.js +5 -0
- package/lib/hooks/useExec/index.js +3 -12
- package/lib/hooks/useFullArguments/index.js +4 -6
- package/lib/hooks/useIfExec/index.js +27 -0
- package/lib/hooks/useIfExec/types.js +5 -0
- package/lib/hooks/useIfReturn/index.js +29 -0
- package/lib/hooks/useIfReturn/types.js +5 -0
- package/lib/hooks/useProvider/index.js +16 -22
- package/lib/hooks/useProviders/index.js +3 -3
- package/lib/hooks/useReducers/index.js +46 -29
- package/lib/hooks/useReturn/index.js +40 -0
- package/lib/hooks/useReturn/types.js +5 -0
- package/lib/hooks/useRootInitializing/index.js +20 -0
- package/lib/hooks/useRootReturn/index.js +30 -0
- package/lib/hooks/useRootReturn/types.js +5 -0
- package/lib/hooks/useStatuses/index.js +47 -21
- package/lib/hooks/useStore/index.js +19 -48
- package/lib/hooks/useThrottleUpdate/index.js +37 -0
- package/lib/hooks/useThrottleUpdate/types.js +5 -0
- package/lib/hooks/useUseCase/index.js +22 -25
- package/lib/hooks/useUseCase/index.test.js +360 -97
- package/lib/methods/cacheCall/index.js +44 -0
- package/lib/methods/cacheCall/types.js +5 -0
- package/lib/methods/cacheCalls/index.js +19 -0
- package/lib/usecases/contextUseCase/index.js +21 -38
- package/lib/usecases/lifecycleEventUseCase/index.js +48 -8
- package/package.json +3 -3
- package/es/enums/ArgumentTypes/index.d.ts +0 -4
- package/es/enums/ArgumentTypes/index.js +0 -5
- package/es/hooks/useArgumentTypes/index.d.ts +0 -3
- package/es/hooks/useArgumentTypes/index.js +0 -14
- package/es/hooks/useConstantEntityReducers/index.d.ts +0 -3
- package/es/hooks/useConstantEntityReducers/index.js +0 -7
- package/es/hooks/useConstantFn/index.d.ts +0 -1
- package/es/hooks/useConstantFn/index.js +0 -10
- package/es/hooks/useConstantReducers/index.d.ts +0 -3
- package/es/hooks/useConstantReducers/index.js +0 -6
- package/es/hooks/useContextualItem/index.d.ts +0 -4
- package/es/hooks/useContextualItem/index.js +0 -31
- package/es/hooks/useContextualItem/types.d.ts +0 -3
- package/es/hooks/useEntityInitializing/index.d.ts +0 -2
- package/es/hooks/useEntityInitializing/index.js +0 -16
- package/es/usecases/methodUseCase/index.d.ts +0 -2
- package/es/usecases/methodUseCase/index.js +0 -72
- package/es/usecases/methodUseCase/types.d.ts +0 -21
- package/lib/enums/ArgumentTypes/index.js +0 -11
- package/lib/hooks/useArgumentTypes/index.js +0 -22
- package/lib/hooks/useConstantEntityReducers/index.js +0 -13
- package/lib/hooks/useConstantFn/index.js +0 -17
- package/lib/hooks/useConstantReducers/index.js +0 -12
- package/lib/hooks/useContextualItem/index.js +0 -37
- package/lib/hooks/useEntityInitializing/index.js +0 -22
- package/lib/usecases/methodUseCase/index.js +0 -79
- /package/es/hooks/{useContextualItem → useChanged}/types.js +0 -0
- /package/es/{usecases/methodUseCase → hooks/useEntityReturn}/types.js +0 -0
- /package/lib/hooks/{useContextualItem → useChanged}/types.js +0 -0
- /package/lib/{usecases/methodUseCase → hooks/useEntityReturn}/types.js +0 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.cacheCall = void 0;
|
|
7
|
+
var _objectUtilsUseCase2 = require("../../usecases/objectUtilsUseCase");
|
|
8
|
+
var cacheCall = exports.cacheCall = function cacheCall(factory, options) {
|
|
9
|
+
var cache;
|
|
10
|
+
var _objectUtilsUseCase = (0, _objectUtilsUseCase2.objectUtilsUseCase)(),
|
|
11
|
+
isEqual = _objectUtilsUseCase.isEqual;
|
|
12
|
+
var _ref = options || {},
|
|
13
|
+
_ref$onShouldCache = _ref.onShouldCache,
|
|
14
|
+
onShouldCache = _ref$onShouldCache === void 0 ? function () {
|
|
15
|
+
return true;
|
|
16
|
+
} : _ref$onShouldCache,
|
|
17
|
+
_ref$onCompare = _ref.onCompare,
|
|
18
|
+
onCompare = _ref$onCompare === void 0 ? function (newArgs, oldArgs) {
|
|
19
|
+
return isEqual(newArgs, oldArgs);
|
|
20
|
+
} : _ref$onCompare;
|
|
21
|
+
return new Proxy(factory, {
|
|
22
|
+
apply: function apply(target, thisArg) {
|
|
23
|
+
var argList = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
24
|
+
var args = argList;
|
|
25
|
+
var cacheable = onShouldCache();
|
|
26
|
+
if (cache && cacheable) {
|
|
27
|
+
var _cache = cache,
|
|
28
|
+
parameters = _cache.parameters,
|
|
29
|
+
_returnValue = _cache.returnValue;
|
|
30
|
+
if (onCompare(parameters, args)) {
|
|
31
|
+
return _returnValue;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
var returnValue = Reflect.apply(target, thisArg, args);
|
|
35
|
+
if (cacheable) {
|
|
36
|
+
cache = {
|
|
37
|
+
parameters: args,
|
|
38
|
+
returnValue: returnValue
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
return returnValue;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.cacheCalls = void 0;
|
|
8
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
+
var _cacheCall = require("../cacheCall");
|
|
10
|
+
var cacheCalls = exports.cacheCalls = function cacheCalls(sourceFactories, options) {
|
|
11
|
+
var cachedFactories = {};
|
|
12
|
+
Object.entries(sourceFactories).forEach(function (_ref) {
|
|
13
|
+
var _ref2 = (0, _slicedToArray2["default"])(_ref, 2),
|
|
14
|
+
key = _ref2[0],
|
|
15
|
+
factory = _ref2[1];
|
|
16
|
+
cachedFactories[key] = (0, _cacheCall.cacheCall)(factory, options);
|
|
17
|
+
});
|
|
18
|
+
return cachedFactories;
|
|
19
|
+
};
|
|
@@ -6,68 +6,52 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.contextUseCase = void 0;
|
|
7
7
|
var _usecases = require("@mic-rexjs/usecases");
|
|
8
8
|
var _react = require("react");
|
|
9
|
-
var _ArgumentTypes = require("../../enums/ArgumentTypes");
|
|
10
|
-
var _Statuses = require("../../enums/Statuses");
|
|
11
9
|
var contextUseCase = exports.contextUseCase = (0, _usecases.createUseCase)(function () {
|
|
12
10
|
var referenceMap = new Map();
|
|
13
|
-
var defaultUseCaseContext = (0, _react.createContext)(null);
|
|
14
11
|
return function () {
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
store: store,
|
|
19
|
-
reducers: reducers,
|
|
20
|
-
statuses: statuses
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
return {
|
|
24
|
-
reducers: reducers,
|
|
25
|
-
statuses: statuses
|
|
26
|
-
};
|
|
12
|
+
var getTypedReferenceMap = function getTypedReferenceMap() {
|
|
13
|
+
return referenceMap;
|
|
27
14
|
};
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
var getContext = function getContext(usecase) {
|
|
16
|
+
var map = getTypedReferenceMap();
|
|
17
|
+
if (!map.has(usecase)) {
|
|
18
|
+
return (0, _react.createContext)(null);
|
|
31
19
|
}
|
|
32
|
-
var
|
|
33
|
-
value =
|
|
20
|
+
var _map$get = map.get(usecase),
|
|
21
|
+
value = _map$get.value;
|
|
34
22
|
return value;
|
|
35
23
|
};
|
|
36
|
-
var registerUseCase = function registerUseCase(usecase
|
|
37
|
-
|
|
38
|
-
|
|
24
|
+
var registerUseCase = function registerUseCase(usecase) {
|
|
25
|
+
var map = getTypedReferenceMap();
|
|
26
|
+
if (map.has(usecase)) {
|
|
27
|
+
var reference = map.get(usecase);
|
|
39
28
|
var value = reference.value,
|
|
40
29
|
times = reference.times;
|
|
41
|
-
|
|
30
|
+
map.set(usecase, {
|
|
42
31
|
value: value,
|
|
43
32
|
times: times + 1
|
|
44
33
|
});
|
|
45
34
|
return value;
|
|
46
35
|
}
|
|
47
|
-
if ((argumentTypes & _ArgumentTypes.ArgumentTypes.Entity) !== _ArgumentTypes.ArgumentTypes.Entity) {
|
|
48
|
-
return defaultUseCaseContext;
|
|
49
|
-
}
|
|
50
36
|
var context = (0, _react.createContext)(null);
|
|
51
|
-
|
|
37
|
+
map.set(usecase, {
|
|
52
38
|
value: context,
|
|
53
39
|
times: 1
|
|
54
40
|
});
|
|
55
41
|
return context;
|
|
56
42
|
};
|
|
57
|
-
var unregisterUseCase = function unregisterUseCase(usecase
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
if (!referenceMap.has(usecase)) {
|
|
43
|
+
var unregisterUseCase = function unregisterUseCase(usecase) {
|
|
44
|
+
var map = getTypedReferenceMap();
|
|
45
|
+
if (!map.has(usecase)) {
|
|
62
46
|
return false;
|
|
63
47
|
}
|
|
64
|
-
var reference =
|
|
48
|
+
var reference = map.get(usecase);
|
|
65
49
|
var value = reference.value,
|
|
66
50
|
times = reference.times;
|
|
67
51
|
if (times === 1) {
|
|
68
|
-
|
|
52
|
+
map["delete"](usecase);
|
|
69
53
|
} else {
|
|
70
|
-
|
|
54
|
+
map.set(usecase, {
|
|
71
55
|
value: value,
|
|
72
56
|
times: times - 1
|
|
73
57
|
});
|
|
@@ -75,8 +59,7 @@ var contextUseCase = exports.contextUseCase = (0, _usecases.createUseCase)(funct
|
|
|
75
59
|
return true;
|
|
76
60
|
};
|
|
77
61
|
return {
|
|
78
|
-
|
|
79
|
-
getUseCaseContext: getUseCaseContext,
|
|
62
|
+
getContext: getContext,
|
|
80
63
|
registerUseCase: registerUseCase,
|
|
81
64
|
unregisterUseCase: unregisterUseCase
|
|
82
65
|
};
|
|
@@ -5,32 +5,72 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.lifecycleEventUseCase = void 0;
|
|
7
7
|
var _usecases = require("@mic-rexjs/usecases");
|
|
8
|
+
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, 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 o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
|
|
9
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
10
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
8
11
|
var lifecycleEventUseCase = exports.lifecycleEventUseCase = (0, _usecases.createUseCase)(function () {
|
|
9
12
|
var map = new Map();
|
|
10
|
-
var
|
|
13
|
+
var eventsList = [];
|
|
14
|
+
var _utilsUseCase = (0, _usecases.utilsUseCase)(),
|
|
15
|
+
createKey = _utilsUseCase.createKey;
|
|
11
16
|
/**
|
|
12
17
|
* 逻辑是:先存,再绑定 `key`,再通过 `key` 获取,最后清除
|
|
13
18
|
*/
|
|
14
19
|
return function () {
|
|
20
|
+
var createLifecycleKey = function createLifecycleKey() {
|
|
21
|
+
return createKey();
|
|
22
|
+
};
|
|
15
23
|
var deleteLifecycleEvents = function deleteLifecycleEvents(key) {
|
|
16
24
|
return map["delete"](key);
|
|
17
25
|
};
|
|
18
26
|
var bindLifecycleEventsKey = function bindLifecycleEventsKey(key) {
|
|
19
|
-
|
|
27
|
+
var length = eventsList.length;
|
|
28
|
+
if (length === 0) {
|
|
20
29
|
return {};
|
|
21
30
|
}
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
31
|
+
var list = eventsList.splice(0);
|
|
32
|
+
var onEvent = function onEvent(propertyKey, args) {
|
|
33
|
+
var returnValue = void 0;
|
|
34
|
+
var _iterator = _createForOfIteratorHelper(list),
|
|
35
|
+
_step;
|
|
36
|
+
try {
|
|
37
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
38
|
+
var _events = _step.value;
|
|
39
|
+
var event = _events[propertyKey];
|
|
40
|
+
if (typeof event !== 'function') {
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
returnValue !== null && returnValue !== void 0 ? returnValue : returnValue = Reflect.apply(event, null, args);
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
46
|
+
_iterator.e(err);
|
|
47
|
+
} finally {
|
|
48
|
+
_iterator.f();
|
|
49
|
+
}
|
|
50
|
+
return returnValue;
|
|
51
|
+
};
|
|
52
|
+
var types = ['onBind', 'onUnbind', 'onAdopt', 'onDiscard', 'onChange', 'onUpdate'];
|
|
53
|
+
var entries = types.map(function (type) {
|
|
54
|
+
var event = function event() {
|
|
55
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
56
|
+
args[_key] = arguments[_key];
|
|
57
|
+
}
|
|
58
|
+
return onEvent(type, args);
|
|
59
|
+
};
|
|
60
|
+
return [type, event];
|
|
61
|
+
});
|
|
62
|
+
var events = Object.fromEntries(entries);
|
|
63
|
+
map.set(key, events);
|
|
64
|
+
return events;
|
|
26
65
|
};
|
|
27
66
|
var getLifecycleEvents = function getLifecycleEvents(key) {
|
|
28
67
|
return map.get(key) || {};
|
|
29
68
|
};
|
|
30
|
-
var setLifecycleEvents = function setLifecycleEvents(
|
|
31
|
-
events
|
|
69
|
+
var setLifecycleEvents = function setLifecycleEvents(events) {
|
|
70
|
+
eventsList.push(events);
|
|
32
71
|
};
|
|
33
72
|
return {
|
|
73
|
+
createLifecycleKey: createLifecycleKey,
|
|
34
74
|
deleteLifecycleEvents: deleteLifecycleEvents,
|
|
35
75
|
setLifecycleEvents: setLifecycleEvents,
|
|
36
76
|
getLifecycleEvents: getLifecycleEvents,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mic-rexjs/usecases-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0-beta.3",
|
|
4
4
|
"description": "React-based solution for use usecases of Clean Architecture",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"peerDependencies": {
|
|
38
|
-
"@mic-rexjs/usecases": "^4.
|
|
38
|
+
"@mic-rexjs/usecases": "^4.9.1",
|
|
39
39
|
"react": ">=16.8.0"
|
|
40
40
|
},
|
|
41
41
|
"dependencies": {
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"@eslint/js": "^10.0.1",
|
|
55
55
|
"@ianvs/prettier-plugin-sort-imports": "^4.7.1",
|
|
56
56
|
"@jest/globals": "^30.3.0",
|
|
57
|
-
"@mic-rexjs/usecases": "^4.
|
|
57
|
+
"@mic-rexjs/usecases": "^4.9.1",
|
|
58
58
|
"@testing-library/dom": "^10.4.1",
|
|
59
59
|
"@testing-library/react": "^16.3.2",
|
|
60
60
|
"@types/node": "^25.6.0",
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import { useConstant } from '../useConstant';
|
|
3
|
-
import { ArgumentTypes } from '../../enums/ArgumentTypes';
|
|
4
|
-
export const useArgumentTypes = args => {
|
|
5
|
-
return useConstant(() => {
|
|
6
|
-
const _args = _slicedToArray(args, 2),
|
|
7
|
-
arg2 = _args[1];
|
|
8
|
-
const type2 = typeof arg2;
|
|
9
|
-
if (type2 === 'function') {
|
|
10
|
-
return ArgumentTypes.Entity;
|
|
11
|
-
}
|
|
12
|
-
return ArgumentTypes.None;
|
|
13
|
-
});
|
|
14
|
-
};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { CreateEntityReducersOptions, ScopedEntityReducers } from '@mic-rexjs/usecases/es/methods/createEntityReducers/types';
|
|
2
|
-
import { EntityReducerMap, EntityReducers, InferableEntityUseCase } from '@mic-rexjs/usecases/es/types';
|
|
3
|
-
export declare const useConstantEntityReducers: <T, TEntityReducers extends EntityReducerMap<T>, TUseCaseOptions extends object = object>(initailEntity: T, usecase: InferableEntityUseCase<T, TEntityReducers & EntityReducers<T>, TUseCaseOptions>, options?: CreateEntityReducersOptions<T, TUseCaseOptions>) => ScopedEntityReducers<T, EntityReducers<T, TEntityReducers>>;
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { useConstant } from '../useConstant';
|
|
2
|
-
import { createEntityReducers } from '@mic-rexjs/usecases';
|
|
3
|
-
export const useConstantEntityReducers = (initailEntity, usecase, options) => {
|
|
4
|
-
return useConstant(() => {
|
|
5
|
-
return createEntityReducers(initailEntity, usecase, options);
|
|
6
|
-
});
|
|
7
|
-
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const useConstantFn: <T>(initialValue: T) => T;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import { useState } from 'react';
|
|
3
|
-
export const useConstantFn = initialValue => {
|
|
4
|
-
const _useState = useState(() => {
|
|
5
|
-
return initialValue;
|
|
6
|
-
}),
|
|
7
|
-
_useState2 = _slicedToArray(_useState, 1),
|
|
8
|
-
value = _useState2[0];
|
|
9
|
-
return value;
|
|
10
|
-
};
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { NonEntitySymbolSet } from '../useUseCase/types';
|
|
2
|
-
import { ReducerMap, SymbolSetTarget, UseCase } from '@mic-rexjs/usecases/es/types';
|
|
3
|
-
export declare const useConstantReducers: <T extends ReducerMap, TUseCaseOptions extends object = object>(usecase: UseCase<T & SymbolSetTarget<NonEntitySymbolSet>, TUseCaseOptions>, options?: TUseCaseOptions) => T;
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { CreateContextualItemFactory } from './types';
|
|
2
|
-
import { Statuses } from '../../enums/Statuses';
|
|
3
|
-
import { Dependencies } from '../../types';
|
|
4
|
-
export declare const useContextualItem: <T>(contextItem: T | null, statuses: Statuses, createFactory: CreateContextualItemFactory<T>, deps?: Dependencies) => T;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { useDepsKey } from '../useDepsKey';
|
|
2
|
-
import { useCreation, useLatest, useMemoizedFn } from 'ahooks';
|
|
3
|
-
import { Statuses } from '../../enums/Statuses';
|
|
4
|
-
import { methodUseCase } from '../../usecases/methodUseCase';
|
|
5
|
-
export const useContextualItem = function (contextItem, statuses, createFactory) {
|
|
6
|
-
let deps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
7
|
-
const depsKey = useDepsKey(deps);
|
|
8
|
-
const factoryRef = useLatest(createFactory);
|
|
9
|
-
const onCache = useMemoizedFn(() => {
|
|
10
|
-
const _methodUseCase = methodUseCase(),
|
|
11
|
-
cacheCall = _methodUseCase.cacheCall;
|
|
12
|
-
const currentFactory = factoryRef.current;
|
|
13
|
-
// 防止在以下 `onCreate()` 多次调用实际 `factory`
|
|
14
|
-
return cacheCall(currentFactory, {
|
|
15
|
-
onCompare() {
|
|
16
|
-
return true;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
});
|
|
20
|
-
const onCreate = useCreation(() => {
|
|
21
|
-
void depsKey;
|
|
22
|
-
return onCache();
|
|
23
|
-
}, [depsKey, onCache]);
|
|
24
|
-
return useCreation(() => {
|
|
25
|
-
const rootEnabled = (statuses & Statuses.RootEnabled) === Statuses.RootEnabled;
|
|
26
|
-
if (!rootEnabled && contextItem) {
|
|
27
|
-
return contextItem;
|
|
28
|
-
}
|
|
29
|
-
return onCreate();
|
|
30
|
-
}, [statuses, contextItem, onCreate]);
|
|
31
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { useExec } from '../useExec';
|
|
2
|
-
import { useRef } from 'react';
|
|
3
|
-
import { Statuses } from '../../enums/Statuses';
|
|
4
|
-
export const useEntityInitializing = statuses => {
|
|
5
|
-
const isInitializingRef = useRef(true);
|
|
6
|
-
const entityRootEnabled = (statuses & Statuses.EntityRootEnabled) === Statuses.EntityRootEnabled;
|
|
7
|
-
return useExec(() => {
|
|
8
|
-
if (!entityRootEnabled) {
|
|
9
|
-
isInitializingRef.current = true;
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
const isInitializing = isInitializingRef.current;
|
|
13
|
-
isInitializingRef.current = false;
|
|
14
|
-
return isInitializing;
|
|
15
|
-
});
|
|
16
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
-
import { objectUtilsUseCase } from '../objectUtilsUseCase';
|
|
3
|
-
export const methodUseCase = () => {
|
|
4
|
-
const _objectUtilsUseCase = objectUtilsUseCase(),
|
|
5
|
-
isEqual = _objectUtilsUseCase.isEqual;
|
|
6
|
-
const cacheCall = (factory, options) => {
|
|
7
|
-
let cache;
|
|
8
|
-
const _ref = options || {},
|
|
9
|
-
_ref$onShouldCache = _ref.onShouldCache,
|
|
10
|
-
onShouldCache = _ref$onShouldCache === void 0 ? () => {
|
|
11
|
-
return true;
|
|
12
|
-
} : _ref$onShouldCache,
|
|
13
|
-
_ref$onCompare = _ref.onCompare,
|
|
14
|
-
onCompare = _ref$onCompare === void 0 ? (newArgs, oldArgs) => {
|
|
15
|
-
return isEqual(newArgs, oldArgs);
|
|
16
|
-
} : _ref$onCompare;
|
|
17
|
-
return function () {
|
|
18
|
-
const cacheable = onShouldCache();
|
|
19
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
20
|
-
args[_key] = arguments[_key];
|
|
21
|
-
}
|
|
22
|
-
if (cache && cacheable) {
|
|
23
|
-
const _cache = cache,
|
|
24
|
-
parameters = _cache.parameters,
|
|
25
|
-
returnValue = _cache.returnValue;
|
|
26
|
-
if (onCompare(parameters, args)) {
|
|
27
|
-
return returnValue;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const returnValue = factory(...args);
|
|
31
|
-
if (cacheable) {
|
|
32
|
-
cache = {
|
|
33
|
-
parameters: args,
|
|
34
|
-
returnValue
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
return returnValue;
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
const cacheCalls = (sourceFactories, options) => {
|
|
41
|
-
const cachedFactories = {};
|
|
42
|
-
Object.entries(sourceFactories).forEach(_ref2 => {
|
|
43
|
-
let _ref3 = _slicedToArray(_ref2, 2),
|
|
44
|
-
key = _ref3[0],
|
|
45
|
-
factory = _ref3[1];
|
|
46
|
-
cachedFactories[key] = cacheCall(factory, options);
|
|
47
|
-
});
|
|
48
|
-
return cachedFactories;
|
|
49
|
-
};
|
|
50
|
-
const captureCalls = (obj, callback) => {
|
|
51
|
-
const newObj = {};
|
|
52
|
-
Object.keys(obj).forEach(key => {
|
|
53
|
-
const value = obj[key];
|
|
54
|
-
if (typeof value === 'function') {
|
|
55
|
-
newObj[key] = function () {
|
|
56
|
-
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
57
|
-
args[_key2] = arguments[_key2];
|
|
58
|
-
}
|
|
59
|
-
return callback(key, args);
|
|
60
|
-
};
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
newObj[key] = value;
|
|
64
|
-
});
|
|
65
|
-
return newObj;
|
|
66
|
-
};
|
|
67
|
-
return {
|
|
68
|
-
cacheCall,
|
|
69
|
-
cacheCalls,
|
|
70
|
-
captureCalls
|
|
71
|
-
};
|
|
72
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Reducers } 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 CacheableFactory> {
|
|
11
|
-
parameters: Parameters<T>;
|
|
12
|
-
returnValue: ReturnType<T>;
|
|
13
|
-
}
|
|
14
|
-
export interface CaptureCallFactory {
|
|
15
|
-
<T>(key: string, args: RestArguments): T;
|
|
16
|
-
}
|
|
17
|
-
export type MethodReducers = Reducers<{
|
|
18
|
-
cacheCall<T extends CacheableFactory>(factory: T, options?: CacheCallOptions): T;
|
|
19
|
-
cacheCalls<T extends Record<string, CacheableFactory>>(sourceFactories: T, options?: CacheCallOptions): T;
|
|
20
|
-
captureCalls<T extends object>(obj: T, callback: CaptureCallFactory): T;
|
|
21
|
-
}>;
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ArgumentTypes = void 0;
|
|
7
|
-
var ArgumentTypes;
|
|
8
|
-
(function (ArgumentTypes) {
|
|
9
|
-
ArgumentTypes[ArgumentTypes["None"] = 0] = "None";
|
|
10
|
-
ArgumentTypes[ArgumentTypes["Entity"] = 2] = "Entity";
|
|
11
|
-
})(ArgumentTypes || (exports.ArgumentTypes = ArgumentTypes = {}));
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.useArgumentTypes = void 0;
|
|
8
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
9
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
|
-
var _useConstant = require("../useConstant");
|
|
11
|
-
var _ArgumentTypes = require("../../enums/ArgumentTypes");
|
|
12
|
-
var useArgumentTypes = exports.useArgumentTypes = function useArgumentTypes(args) {
|
|
13
|
-
return (0, _useConstant.useConstant)(function () {
|
|
14
|
-
var _args = (0, _slicedToArray2["default"])(args, 2),
|
|
15
|
-
arg2 = _args[1];
|
|
16
|
-
var type2 = (0, _typeof2["default"])(arg2);
|
|
17
|
-
if (type2 === 'function') {
|
|
18
|
-
return _ArgumentTypes.ArgumentTypes.Entity;
|
|
19
|
-
}
|
|
20
|
-
return _ArgumentTypes.ArgumentTypes.None;
|
|
21
|
-
});
|
|
22
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useConstantEntityReducers = void 0;
|
|
7
|
-
var _useConstant = require("../useConstant");
|
|
8
|
-
var _usecases = require("@mic-rexjs/usecases");
|
|
9
|
-
var useConstantEntityReducers = exports.useConstantEntityReducers = function useConstantEntityReducers(initailEntity, usecase, options) {
|
|
10
|
-
return (0, _useConstant.useConstant)(function () {
|
|
11
|
-
return (0, _usecases.createEntityReducers)(initailEntity, usecase, options);
|
|
12
|
-
});
|
|
13
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.useConstantFn = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _react = require("react");
|
|
10
|
-
var useConstantFn = exports.useConstantFn = function useConstantFn(initialValue) {
|
|
11
|
-
var _useState = (0, _react.useState)(function () {
|
|
12
|
-
return initialValue;
|
|
13
|
-
}),
|
|
14
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 1),
|
|
15
|
-
value = _useState2[0];
|
|
16
|
-
return value;
|
|
17
|
-
};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useConstantReducers = void 0;
|
|
7
|
-
var _useConstant = require("../useConstant");
|
|
8
|
-
var useConstantReducers = exports.useConstantReducers = function useConstantReducers(usecase, options) {
|
|
9
|
-
return (0, _useConstant.useConstant)(function () {
|
|
10
|
-
return usecase(options);
|
|
11
|
-
});
|
|
12
|
-
};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useContextualItem = void 0;
|
|
7
|
-
var _useDepsKey = require("../useDepsKey");
|
|
8
|
-
var _ahooks = require("ahooks");
|
|
9
|
-
var _Statuses = require("../../enums/Statuses");
|
|
10
|
-
var _methodUseCase2 = require("../../usecases/methodUseCase");
|
|
11
|
-
var useContextualItem = exports.useContextualItem = function useContextualItem(contextItem, statuses, createFactory) {
|
|
12
|
-
var deps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
13
|
-
var depsKey = (0, _useDepsKey.useDepsKey)(deps);
|
|
14
|
-
var factoryRef = (0, _ahooks.useLatest)(createFactory);
|
|
15
|
-
var onCache = (0, _ahooks.useMemoizedFn)(function () {
|
|
16
|
-
var _methodUseCase = (0, _methodUseCase2.methodUseCase)(),
|
|
17
|
-
cacheCall = _methodUseCase.cacheCall;
|
|
18
|
-
var currentFactory = factoryRef.current;
|
|
19
|
-
// 防止在以下 `onCreate()` 多次调用实际 `factory`
|
|
20
|
-
return cacheCall(currentFactory, {
|
|
21
|
-
onCompare: function onCompare() {
|
|
22
|
-
return true;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
var onCreate = (0, _ahooks.useCreation)(function () {
|
|
27
|
-
void depsKey;
|
|
28
|
-
return onCache();
|
|
29
|
-
}, [depsKey, onCache]);
|
|
30
|
-
return (0, _ahooks.useCreation)(function () {
|
|
31
|
-
var rootEnabled = (statuses & _Statuses.Statuses.RootEnabled) === _Statuses.Statuses.RootEnabled;
|
|
32
|
-
if (!rootEnabled && contextItem) {
|
|
33
|
-
return contextItem;
|
|
34
|
-
}
|
|
35
|
-
return onCreate();
|
|
36
|
-
}, [statuses, contextItem, onCreate]);
|
|
37
|
-
};
|