@mic-rexjs/usecases-react 3.6.3 → 4.0.0-beta.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 (68) hide show
  1. package/dist/index.min.js +1 -1
  2. package/es/classes/OptionsSet/index.d.ts +6 -0
  3. package/es/classes/OptionsSet/index.js +44 -0
  4. package/es/classes/OptionsSet/types.d.ts +8 -0
  5. package/es/hooks/useContextValue/index.d.ts +6 -0
  6. package/es/hooks/useContextValue/index.js +20 -0
  7. package/es/hooks/useContextualItem/index.d.ts +2 -2
  8. package/es/hooks/useContextualItem/index.js +8 -28
  9. package/es/hooks/useEntity/index.d.ts +1 -1
  10. package/es/hooks/useEntity/index.js +21 -15
  11. package/es/hooks/useExec/index.d.ts +2 -2
  12. package/es/hooks/useExec/index.js +19 -6
  13. package/es/hooks/useExec/types.d.ts +3 -0
  14. package/es/hooks/useFullArguments/types.d.ts +2 -2
  15. package/es/hooks/useOptions/index.d.ts +5 -0
  16. package/es/hooks/useOptions/index.js +54 -0
  17. package/es/hooks/useOptions/types.d.ts +5 -0
  18. package/es/hooks/useOptionsSet/index.d.ts +5 -0
  19. package/es/hooks/useOptionsSet/index.js +16 -0
  20. package/es/hooks/useProvider/index.d.ts +1 -3
  21. package/es/hooks/useProvider/index.js +2 -10
  22. package/es/hooks/useReducers/index.d.ts +1 -1
  23. package/es/hooks/useReducers/index.js +6 -25
  24. package/es/hooks/useRootCreation/index.d.ts +4 -0
  25. package/es/hooks/useRootCreation/index.js +20 -0
  26. package/es/hooks/useRootCreation/types.d.ts +3 -0
  27. package/es/hooks/useRootCreation/types.js +1 -0
  28. package/es/hooks/useStore/index.js +7 -12
  29. package/es/hooks/useUseCase/index.js +12 -6
  30. package/es/hooks/useUseCase/index.test.js +286 -126
  31. package/es/hooks/useUseCase/types.d.ts +4 -5
  32. package/es/methods/cacheCall/index.d.ts +2 -0
  33. package/es/methods/cacheCall/index.js +38 -0
  34. package/es/methods/cacheCall/types.d.ts +12 -0
  35. package/es/methods/cacheCall/types.js +1 -0
  36. package/es/methods/cacheCalls/index.d.ts +2 -0
  37. package/es/methods/cacheCalls/index.js +12 -0
  38. package/es/usecases/contextUseCase/types.d.ts +3 -1
  39. package/es/usecases/lifecycleEventUseCase/types.d.ts +14 -0
  40. package/es/usecases/lifecycleUseCase/index.js +5 -1
  41. package/lib/classes/OptionsSet/index.js +94 -0
  42. package/lib/hooks/useContextValue/index.js +26 -0
  43. package/lib/hooks/useContextualItem/index.js +8 -28
  44. package/lib/hooks/useEntity/index.js +20 -14
  45. package/lib/hooks/useExec/index.js +18 -5
  46. package/lib/hooks/useOptions/index.js +61 -0
  47. package/lib/hooks/useOptionsSet/index.js +22 -0
  48. package/lib/hooks/useProvider/index.js +1 -9
  49. package/lib/hooks/useReducers/index.js +8 -31
  50. package/lib/hooks/useRootCreation/index.js +26 -0
  51. package/lib/hooks/useRootCreation/types.js +5 -0
  52. package/lib/hooks/useStore/index.js +7 -12
  53. package/lib/hooks/useUseCase/index.js +13 -7
  54. package/lib/hooks/useUseCase/index.test.js +322 -127
  55. package/lib/methods/cacheCall/index.js +44 -0
  56. package/lib/methods/cacheCall/types.js +5 -0
  57. package/lib/methods/cacheCalls/index.js +19 -0
  58. package/lib/usecases/lifecycleUseCase/index.js +5 -1
  59. package/package.json +3 -3
  60. package/es/hooks/useContextualItem/types.d.ts +0 -3
  61. package/es/usecases/methodUseCase/index.d.ts +0 -2
  62. package/es/usecases/methodUseCase/index.js +0 -72
  63. package/es/usecases/methodUseCase/types.d.ts +0 -21
  64. package/lib/usecases/methodUseCase/index.js +0 -79
  65. /package/es/{hooks/useContextualItem → classes/OptionsSet}/types.js +0 -0
  66. /package/es/{usecases/methodUseCase → hooks/useOptions}/types.js +0 -0
  67. /package/lib/{hooks/useContextualItem → classes/OptionsSet}/types.js +0 -0
  68. /package/lib/{usecases/methodUseCase → hooks/useOptions}/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,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -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
+ };
@@ -12,7 +12,9 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
12
12
  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; }
13
13
  var lifecycleUseCase = exports.lifecycleUseCase = function lifecycleUseCase() {
14
14
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
15
- var onBind = options.onBind,
15
+ var onAdopt = options.onAdopt,
16
+ onDiscard = options.onDiscard,
17
+ onBind = options.onBind,
16
18
  onUnbind = options.onUnbind,
17
19
  onChange = options.onChange,
18
20
  onUpdate = options.onUpdate;
@@ -20,6 +22,8 @@ var lifecycleUseCase = exports.lifecycleUseCase = function lifecycleUseCase() {
20
22
  setLifecycleEvents = _lifecycleEventUseCas.setLifecycleEvents;
21
23
  var entityReducers = (0, _usecases.entityUseCase)();
22
24
  setLifecycleEvents({
25
+ onAdopt: onAdopt,
26
+ onDiscard: onDiscard,
23
27
  onBind: onBind,
24
28
  onUnbind: onUnbind,
25
29
  onChange: onChange,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mic-rexjs/usecases-react",
3
- "version": "3.6.3",
3
+ "version": "4.0.0-beta.0",
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.8.0",
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.8.0",
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,3 +0,0 @@
1
- export interface CreateContextualItemFactory<T> {
2
- (): T;
3
- }
@@ -1,2 +0,0 @@
1
- import { MethodReducers } from './types';
2
- export declare const methodUseCase: () => MethodReducers;
@@ -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,79 +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.methodUseCase = void 0;
8
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
- var _objectUtilsUseCase2 = require("../objectUtilsUseCase");
10
- var methodUseCase = exports.methodUseCase = function methodUseCase() {
11
- var _objectUtilsUseCase = (0, _objectUtilsUseCase2.objectUtilsUseCase)(),
12
- isEqual = _objectUtilsUseCase.isEqual;
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 isEqual(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
- };