@mic-rexjs/usecases-react 4.0.0-beta.0 → 4.0.0-beta.4

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 (150) hide show
  1. package/dist/index.min.js +1 -1
  2. package/dist/index.min.js.LICENSE.txt +2 -0
  3. package/es/components/UseCaseFragment/index.js +2 -2
  4. package/es/enums/Statuses/index.d.ts +86 -10
  5. package/es/enums/Statuses/index.js +86 -10
  6. package/es/hooks/useAlternateStatuses/index.d.ts +2 -0
  7. package/es/hooks/useAlternateStatuses/index.js +16 -0
  8. package/es/hooks/useChanged/index.d.ts +2 -0
  9. package/es/hooks/useChanged/index.js +17 -0
  10. package/es/hooks/useChanged/types.d.ts +3 -0
  11. package/es/hooks/useContext/index.d.ts +3 -4
  12. package/es/hooks/useContext/index.js +17 -15
  13. package/es/hooks/useContext/index.test.js +13 -24
  14. package/es/hooks/useContextValue/index.d.ts +3 -4
  15. package/es/hooks/useContextValue/index.js +9 -16
  16. package/es/hooks/useDepsKey/index.js +11 -9
  17. package/es/hooks/useEntity/index.d.ts +3 -2
  18. package/es/hooks/useEntity/index.js +62 -59
  19. package/es/hooks/useEntityReturn/index.d.ts +5 -0
  20. package/es/hooks/useEntityReturn/index.js +15 -0
  21. package/es/hooks/useEntityReturn/types.d.ts +7 -0
  22. package/es/hooks/useEntityRootExec/index.d.ts +5 -0
  23. package/es/hooks/useEntityRootExec/index.js +7 -0
  24. package/es/hooks/useEntityRootExec/types.d.ts +7 -0
  25. package/es/hooks/useEntityRootReturn/index.d.ts +5 -0
  26. package/es/hooks/useEntityRootReturn/index.js +14 -0
  27. package/es/hooks/useEntityRootReturn/types.d.ts +7 -0
  28. package/es/hooks/useEntityRootReturn/types.js +1 -0
  29. package/es/hooks/useExec/index.d.ts +2 -3
  30. package/es/hooks/useExec/index.js +3 -25
  31. package/es/hooks/useExec/types.d.ts +7 -2
  32. package/es/hooks/useFullArguments/index.d.ts +2 -3
  33. package/es/hooks/useFullArguments/index.js +4 -6
  34. package/es/hooks/useIfExec/index.d.ts +2 -0
  35. package/es/hooks/useIfExec/index.js +20 -0
  36. package/es/hooks/useIfExec/types.d.ts +6 -0
  37. package/es/hooks/useIfExec/types.js +1 -0
  38. package/es/hooks/useIfReturn/index.d.ts +2 -0
  39. package/es/hooks/useIfReturn/index.js +22 -0
  40. package/es/hooks/useIfReturn/types.d.ts +6 -0
  41. package/es/hooks/useIfReturn/types.js +1 -0
  42. package/es/hooks/useProvider/index.d.ts +3 -3
  43. package/es/hooks/useProvider/index.js +15 -13
  44. package/es/hooks/useProviders/index.js +4 -4
  45. package/es/hooks/useReducers/index.d.ts +5 -4
  46. package/es/hooks/useReducers/index.js +47 -10
  47. package/es/hooks/useReturn/index.d.ts +2 -0
  48. package/es/hooks/useReturn/index.js +33 -0
  49. package/es/hooks/useReturn/types.d.ts +11 -0
  50. package/es/hooks/useReturn/types.js +1 -0
  51. package/es/hooks/useRootInitializing/index.d.ts +2 -0
  52. package/es/hooks/useRootInitializing/index.js +14 -0
  53. package/es/hooks/useRootReturn/index.d.ts +5 -0
  54. package/es/hooks/useRootReturn/index.js +22 -0
  55. package/es/hooks/useRootReturn/types.d.ts +14 -0
  56. package/es/hooks/useRootReturn/types.js +1 -0
  57. package/es/hooks/useStatuses/index.d.ts +4 -4
  58. package/es/hooks/useStatuses/index.js +46 -21
  59. package/es/hooks/useStore/index.d.ts +3 -3
  60. package/es/hooks/useStore/index.js +24 -47
  61. package/es/hooks/useThrottleUpdate/index.d.ts +2 -0
  62. package/es/hooks/useThrottleUpdate/index.js +31 -0
  63. package/es/hooks/useThrottleUpdate/types.d.ts +3 -0
  64. package/es/hooks/useThrottleUpdate/types.js +1 -0
  65. package/es/hooks/useUseCase/index.js +18 -27
  66. package/es/hooks/useUseCase/index.test.js +415 -236
  67. package/es/hooks/useUseCase/types.d.ts +13 -2
  68. package/es/types.d.ts +2 -1
  69. package/es/usecases/contextUseCase/index.js +21 -38
  70. package/es/usecases/contextUseCase/types.d.ts +6 -9
  71. package/es/usecases/lifecycleEventUseCase/index.js +37 -9
  72. package/es/usecases/lifecycleEventUseCase/types.d.ts +11 -8
  73. package/lib/components/UseCaseFragment/index.js +2 -2
  74. package/lib/enums/Statuses/index.js +86 -10
  75. package/lib/hooks/useAlternateStatuses/index.js +22 -0
  76. package/lib/hooks/useChanged/index.js +23 -0
  77. package/lib/hooks/useContext/index.js +19 -17
  78. package/lib/hooks/useContext/index.test.js +13 -24
  79. package/lib/hooks/useContextValue/index.js +8 -15
  80. package/lib/hooks/useDepsKey/index.js +10 -8
  81. package/lib/hooks/useEntity/index.js +93 -62
  82. package/lib/hooks/useEntityReturn/index.js +22 -0
  83. package/lib/hooks/useEntityRootExec/index.js +13 -0
  84. package/lib/hooks/useEntityRootReturn/index.js +21 -0
  85. package/lib/hooks/useEntityRootReturn/types.js +5 -0
  86. package/lib/hooks/useExec/index.js +3 -25
  87. package/lib/hooks/useFullArguments/index.js +4 -6
  88. package/lib/hooks/useIfExec/index.js +27 -0
  89. package/lib/hooks/useIfExec/types.js +5 -0
  90. package/lib/hooks/useIfReturn/index.js +29 -0
  91. package/lib/hooks/useIfReturn/types.js +5 -0
  92. package/lib/hooks/useProvider/index.js +15 -13
  93. package/lib/hooks/useProviders/index.js +3 -3
  94. package/lib/hooks/useReducers/index.js +50 -10
  95. package/lib/hooks/useReturn/index.js +40 -0
  96. package/lib/hooks/useReturn/types.js +5 -0
  97. package/lib/hooks/useRootInitializing/index.js +20 -0
  98. package/lib/hooks/useRootReturn/index.js +30 -0
  99. package/lib/hooks/useRootReturn/types.js +5 -0
  100. package/lib/hooks/useStatuses/index.js +47 -21
  101. package/lib/hooks/useStore/index.js +22 -46
  102. package/lib/hooks/useThrottleUpdate/index.js +37 -0
  103. package/lib/hooks/useThrottleUpdate/types.js +5 -0
  104. package/lib/hooks/useUseCase/index.js +18 -27
  105. package/lib/hooks/useUseCase/index.test.js +458 -280
  106. package/lib/usecases/contextUseCase/index.js +21 -38
  107. package/lib/usecases/lifecycleEventUseCase/index.js +48 -8
  108. package/package.json +1 -1
  109. package/es/classes/OptionsSet/index.d.ts +0 -6
  110. package/es/classes/OptionsSet/index.js +0 -44
  111. package/es/classes/OptionsSet/types.d.ts +0 -8
  112. package/es/enums/ArgumentTypes/index.d.ts +0 -4
  113. package/es/enums/ArgumentTypes/index.js +0 -5
  114. package/es/hooks/useArgumentTypes/index.d.ts +0 -3
  115. package/es/hooks/useArgumentTypes/index.js +0 -14
  116. package/es/hooks/useConstantEntityReducers/index.d.ts +0 -3
  117. package/es/hooks/useConstantEntityReducers/index.js +0 -7
  118. package/es/hooks/useConstantFn/index.d.ts +0 -1
  119. package/es/hooks/useConstantFn/index.js +0 -10
  120. package/es/hooks/useConstantReducers/index.d.ts +0 -3
  121. package/es/hooks/useConstantReducers/index.js +0 -6
  122. package/es/hooks/useContextualItem/index.d.ts +0 -4
  123. package/es/hooks/useContextualItem/index.js +0 -11
  124. package/es/hooks/useEntityInitializing/index.d.ts +0 -2
  125. package/es/hooks/useEntityInitializing/index.js +0 -16
  126. package/es/hooks/useOptions/index.d.ts +0 -5
  127. package/es/hooks/useOptions/index.js +0 -54
  128. package/es/hooks/useOptions/types.d.ts +0 -5
  129. package/es/hooks/useOptionsSet/index.d.ts +0 -5
  130. package/es/hooks/useOptionsSet/index.js +0 -16
  131. package/es/hooks/useRootCreation/index.d.ts +0 -4
  132. package/es/hooks/useRootCreation/index.js +0 -20
  133. package/es/hooks/useRootCreation/types.d.ts +0 -3
  134. package/lib/classes/OptionsSet/index.js +0 -94
  135. package/lib/enums/ArgumentTypes/index.js +0 -11
  136. package/lib/hooks/useArgumentTypes/index.js +0 -22
  137. package/lib/hooks/useConstantEntityReducers/index.js +0 -13
  138. package/lib/hooks/useConstantFn/index.js +0 -17
  139. package/lib/hooks/useConstantReducers/index.js +0 -12
  140. package/lib/hooks/useContextualItem/index.js +0 -17
  141. package/lib/hooks/useEntityInitializing/index.js +0 -22
  142. package/lib/hooks/useOptions/index.js +0 -61
  143. package/lib/hooks/useOptionsSet/index.js +0 -22
  144. package/lib/hooks/useRootCreation/index.js +0 -26
  145. /package/es/{classes/OptionsSet → hooks/useChanged}/types.js +0 -0
  146. /package/es/hooks/{useOptions → useEntityReturn}/types.js +0 -0
  147. /package/es/hooks/{useRootCreation → useEntityRootExec}/types.js +0 -0
  148. /package/lib/{classes/OptionsSet → hooks/useChanged}/types.js +0 -0
  149. /package/lib/hooks/{useOptions → useEntityReturn}/types.js +0 -0
  150. /package/lib/hooks/{useRootCreation → useEntityRootExec}/types.js +0 -0
@@ -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 createContextValue = function createContextValue(store, reducers, statuses) {
16
- if ((statuses & _Statuses.Statuses.EntityEnabled) === _Statuses.Statuses.EntityEnabled) {
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 getUseCaseContext = function getUseCaseContext(usecase) {
29
- if (!referenceMap.has(usecase)) {
30
- return defaultUseCaseContext;
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 _referenceMap$get = referenceMap.get(usecase),
33
- value = _referenceMap$get.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, argumentTypes) {
37
- if (referenceMap.has(usecase)) {
38
- var reference = referenceMap.get(usecase);
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
- referenceMap.set(usecase, {
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
- referenceMap.set(usecase, {
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, argumentTypes) {
58
- if ((argumentTypes & _ArgumentTypes.ArgumentTypes.Entity) !== _ArgumentTypes.ArgumentTypes.Entity) {
59
- return false;
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 = referenceMap.get(usecase);
48
+ var reference = map.get(usecase);
65
49
  var value = reference.value,
66
50
  times = reference.times;
67
51
  if (times === 1) {
68
- referenceMap["delete"](usecase);
52
+ map["delete"](usecase);
69
53
  } else {
70
- referenceMap.set(usecase, {
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
- createContextValue: createContextValue,
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 events = null;
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
- if (events === null) {
27
+ var length = eventsList.length;
28
+ if (length === 0) {
20
29
  return {};
21
30
  }
22
- var currentEvents = events;
23
- events = null;
24
- map.set(key, currentEvents);
25
- return currentEvents;
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(e) {
31
- events = e;
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": "4.0.0-beta.0",
3
+ "version": "4.0.0-beta.4",
4
4
  "description": "React-based solution for use usecases of Clean Architecture",
5
5
  "private": false,
6
6
  "sideEffects": false,
@@ -1,6 +0,0 @@
1
- import { EventParameters, EventReturnType } from './types';
2
- export declare class OptionsSet<T = object> extends Set<T> {
3
- #private;
4
- add(options: T, root?: boolean): this;
5
- apply<K extends keyof T, TThis>(type: K, thisArgument: TThis, argumentsList: EventParameters<T[K]>): EventReturnType<T[K]>;
6
- }
@@ -1,44 +0,0 @@
1
- function _classPrivateFieldInitSpec(e, t, a) { _checkPrivateRedeclaration(e, t), t.set(e, a); }
2
- function _checkPrivateRedeclaration(e, t) { if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object"); }
3
- function _classPrivateFieldGet(s, a) { return s.get(_assertClassBrand(s, a)); }
4
- function _classPrivateFieldSet(s, a, r) { return s.set(_assertClassBrand(s, a), r), r; }
5
- function _assertClassBrand(e, t, n) { if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n; throw new TypeError("Private element is not present on this object"); }
6
- var _rootOptions = /*#__PURE__*/new WeakMap();
7
- export class OptionsSet extends Set {
8
- constructor() {
9
- super(...arguments);
10
- _classPrivateFieldInitSpec(this, _rootOptions, null);
11
- }
12
- add(options, root) {
13
- if (typeof options !== 'object') {
14
- return this;
15
- }
16
- if (root) {
17
- _classPrivateFieldSet(_rootOptions, this, options);
18
- }
19
- super.add(options);
20
- return this;
21
- }
22
- apply(type, thisArgument, argumentsList) {
23
- let returnValue;
24
- const rootOptions = _classPrivateFieldGet(_rootOptions, this);
25
- const _ref = rootOptions || {},
26
- rootEvent = _ref[type];
27
- if (typeof rootEvent === 'function') {
28
- // 最先调用根节点的事件
29
- returnValue = Reflect.apply(rootEvent, thisArgument, argumentsList);
30
- }
31
- for (const options of this) {
32
- if (options === rootOptions) {
33
- continue;
34
- }
35
- const event = options[type];
36
- if (typeof event !== 'function') {
37
- continue;
38
- }
39
- // 非根节点事件,不处理返回值
40
- Reflect.apply(event, thisArgument, argumentsList);
41
- }
42
- return returnValue;
43
- }
44
- }
@@ -1,8 +0,0 @@
1
- import { RestArguments } from '@mic-rexjs/usecases/es/types';
2
- export type EventParameters<T> = T extends (...args: infer TArgs) => unknown ? TArgs : [];
3
- export type EventReturnType<T> = T extends (...args: infer TArgs) => infer TTReturnType ? TTReturnType : void;
4
- export type EventOptionKeys<T, K extends keyof T = keyof T> = K extends `on${Capitalize<string>}` ? NonNullable<T[K]> extends (...args: RestArguments) => unknown ? K : never : never;
5
- export type VoidifyEventOption<T> = T extends (...args: infer TArgs) => unknown ? (...args: TArgs) => void : never;
6
- export type VoidifyEventOptions<T> = {
7
- [K in keyof T as K extends EventOptionKeys<T> ? K : never]: VoidifyEventOption<T[K]>;
8
- };
@@ -1,4 +0,0 @@
1
- export declare enum ArgumentTypes {
2
- None = 0,
3
- Entity = 2
4
- }
@@ -1,5 +0,0 @@
1
- export var ArgumentTypes;
2
- (function (ArgumentTypes) {
3
- ArgumentTypes[ArgumentTypes["None"] = 0] = "None";
4
- ArgumentTypes[ArgumentTypes["Entity"] = 2] = "Entity";
5
- })(ArgumentTypes || (ArgumentTypes = {}));
@@ -1,3 +0,0 @@
1
- import { UseCaseHookParameters } from '../useUseCase/types';
2
- import { ArgumentTypes } from '../../enums/ArgumentTypes';
3
- export declare const useArgumentTypes: (args: UseCaseHookParameters) => ArgumentTypes;
@@ -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,6 +0,0 @@
1
- import { useConstant } from '../useConstant';
2
- export const useConstantReducers = (usecase, options) => {
3
- return useConstant(() => {
4
- return usecase(options);
5
- });
6
- };
@@ -1,4 +0,0 @@
1
- import { RootCreationCallback } from '../useRootCreation/types';
2
- import { Statuses } from '../../enums/Statuses';
3
- import { Dependencies } from '../../types';
4
- export declare const useContextualItem: <T>(contextItem: T | null, statuses: Statuses, callback: RootCreationCallback<T>, deps?: Dependencies) => T;
@@ -1,11 +0,0 @@
1
- import { useRootCreation } from '../useRootCreation';
2
- import { Statuses } from '../../enums/Statuses';
3
- export const useContextualItem = function (contextItem, statuses, callback) {
4
- let deps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
5
- const rootEnabled = (statuses & Statuses.RootEnabled) === Statuses.RootEnabled;
6
- const rootItem = useRootCreation(statuses, callback, false, deps);
7
- if (rootEnabled) {
8
- return rootItem;
9
- }
10
- return contextItem;
11
- };
@@ -1,2 +0,0 @@
1
- import { Statuses } from '../../enums/Statuses';
2
- export declare const useEntityInitializing: (statuses: Statuses) => boolean;
@@ -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,5 +0,0 @@
1
- import { OptionsHookResult } from './types';
2
- import { OptionsSet } from '../../classes/OptionsSet';
3
- import { Statuses } from '../../enums/Statuses';
4
- import { Dependencies } from '../../types';
5
- export declare const useOptions: <T, TOptions extends object>(options: TOptions, optionsSet: OptionsSet<TOptions>, statuses: Statuses, deps?: Dependencies) => OptionsHookResult<T, TOptions>;
@@ -1,54 +0,0 @@
1
- import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
- const _excluded = ["watch", "onChange"];
3
- import { useExec } from '../useExec';
4
- import { useRootCreation } from '../useRootCreation';
5
- import { Statuses } from '../../enums/Statuses';
6
- export const useOptions = function (options, optionsSet, statuses) {
7
- let deps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
8
- const entityEnabled = (statuses & Statuses.EntityEnabled) === Statuses.EntityEnabled;
9
- const entityRootEnabled = (statuses & Statuses.EntityRootEnabled) === Statuses.EntityRootEnabled;
10
- const watch = options.watch,
11
- onChange = options.onChange,
12
- restOptions = _objectWithoutProperties(options, _excluded);
13
- const _options$options = options.options,
14
- propertyOptions = _options$options === void 0 ? restOptions : _options$options;
15
- const contextualOptions = propertyOptions;
16
- const hookOptions = entityEnabled ? {
17
- watch,
18
- onChange
19
- } : {};
20
- const onProxyEvent = propertyName => {
21
- return new Proxy(() => {}, {
22
- apply(fn, thisArgument, argumentList) {
23
- return optionsSet.apply(propertyName, thisArgument, argumentList);
24
- }
25
- });
26
- };
27
- const onGet = (target, propertyName, receiver) => {
28
- const isStringProperty = typeof propertyName === 'string';
29
- const isEvent = isStringProperty && /^on[A-Z]/.test(propertyName);
30
- if (!isEvent) {
31
- return Reflect.get(target, propertyName, receiver);
32
- }
33
- return onProxyEvent(propertyName);
34
- };
35
- const rootOptions = useRootCreation(statuses, () => {
36
- return new Proxy(contextualOptions, {
37
- get: onGet
38
- });
39
- }, true, deps);
40
- const entityUseCaseOptions = rootOptions || contextualOptions;
41
- const usecaseOptions = entityEnabled ? entityUseCaseOptions : options;
42
- useExec(() => {
43
- if (!entityEnabled) {
44
- return;
45
- }
46
- optionsSet.add(contextualOptions, entityRootEnabled);
47
- }, () => {
48
- optionsSet.delete(contextualOptions);
49
- });
50
- return {
51
- hookOptions,
52
- usecaseOptions
53
- };
54
- };
@@ -1,5 +0,0 @@
1
- import { ContextualUseCaseHookOptions } from '../useUseCase/types';
2
- export interface OptionsHookResult<T, TOptions extends object> {
3
- hookOptions: ContextualUseCaseHookOptions<T>;
4
- usecaseOptions: TOptions;
5
- }
@@ -1,5 +0,0 @@
1
- import { ReducerMap } from '@mic-rexjs/usecases/es/types';
2
- import { OptionsSet } from '../../classes/OptionsSet';
3
- import { Statuses } from '../../enums/Statuses';
4
- import { EntityUseCaseContextValue, UseCaseContext } from '../../usecases/contextUseCase/types';
5
- export declare const useOptionsSet: <T, TReducers extends ReducerMap, TOptions extends object>(context: UseCaseContext<EntityUseCaseContextValue<T, TReducers, TOptions>>, statuses: Statuses) => OptionsSet<TOptions>;
@@ -1,16 +0,0 @@
1
- import { useRootCreation } from '../useRootCreation';
2
- import { useContext } from 'react';
3
- import { OptionsSet } from '../../classes/OptionsSet';
4
- export const useOptionsSet = (context, statuses) => {
5
- // 过滤掉三个特殊属性
6
- const contextValue = useContext(context);
7
- const _ref = contextValue || {},
8
- contextOptionsSet = _ref.optionsSet;
9
- const rootEventsSet = useRootCreation(statuses, () => {
10
- return new OptionsSet();
11
- });
12
- if (rootEventsSet) {
13
- return rootEventsSet;
14
- }
15
- return contextOptionsSet;
16
- };
@@ -1,4 +0,0 @@
1
- import { RootCreationCallback } from './types';
2
- import { Statuses } from '../../enums/Statuses';
3
- import { Dependencies } from '../../types';
4
- export declare const useRootCreation: <T>(statuses: Statuses, callback: RootCreationCallback<T>, shouldCheckEntity?: boolean, deps?: Dependencies) => T | null;
@@ -1,20 +0,0 @@
1
- import { useDepsKey } from '../useDepsKey';
2
- import { useCreation, useMemoizedFn } from 'ahooks';
3
- import { Statuses } from '../../enums/Statuses';
4
- export const useRootCreation = function (statuses, callback) {
5
- let shouldCheckEntity = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
6
- let deps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
7
- const depsKey = useDepsKey(deps);
8
- const targetStatuses = shouldCheckEntity ? Statuses.EntityRootEnabled : Statuses.RootEnabled;
9
- const rootEnabled = (statuses & targetStatuses) === targetStatuses;
10
- const onInit = useMemoizedFn(() => {
11
- return callback();
12
- });
13
- return useCreation(() => {
14
- void depsKey;
15
- if (!rootEnabled) {
16
- return null;
17
- }
18
- return onInit();
19
- }, [rootEnabled, depsKey, onInit]);
20
- };
@@ -1,3 +0,0 @@
1
- export interface RootCreationCallback<T> {
2
- (): T;
3
- }
@@ -1,94 +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.OptionsSet = void 0;
8
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
12
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
13
- var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
14
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
15
- var _wrapNativeSuper2 = _interopRequireDefault(require("@babel/runtime/helpers/wrapNativeSuper"));
16
- 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; } } }; }
17
- 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; } }
18
- 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; }
19
- function _callSuper(t, o, e) { return o = (0, _getPrototypeOf2["default"])(o), (0, _possibleConstructorReturn2["default"])(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], (0, _getPrototypeOf2["default"])(t).constructor) : o.apply(t, e)); }
20
- function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
21
- function _superPropGet(t, o, e, r) { var p = (0, _get2["default"])((0, _getPrototypeOf2["default"])(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
22
- function _classPrivateFieldInitSpec(e, t, a) {
23
- _checkPrivateRedeclaration(e, t), t.set(e, a);
24
- }
25
- function _checkPrivateRedeclaration(e, t) {
26
- if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
27
- }
28
- function _classPrivateFieldGet(s, a) {
29
- return s.get(_assertClassBrand(s, a));
30
- }
31
- function _classPrivateFieldSet(s, a, r) {
32
- return s.set(_assertClassBrand(s, a), r), r;
33
- }
34
- function _assertClassBrand(e, t, n) {
35
- if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
36
- throw new TypeError("Private element is not present on this object");
37
- }
38
- var _rootOptions = /*#__PURE__*/new WeakMap();
39
- var OptionsSet = exports.OptionsSet = /*#__PURE__*/function (_Set) {
40
- function OptionsSet() {
41
- var _this;
42
- (0, _classCallCheck2["default"])(this, OptionsSet);
43
- _this = _callSuper(this, OptionsSet, arguments);
44
- _classPrivateFieldInitSpec(_this, _rootOptions, null);
45
- return _this;
46
- }
47
- (0, _inherits2["default"])(OptionsSet, _Set);
48
- return (0, _createClass2["default"])(OptionsSet, [{
49
- key: "add",
50
- value: function add(options, root) {
51
- if ((0, _typeof2["default"])(options) !== 'object') {
52
- return this;
53
- }
54
- if (root) {
55
- _classPrivateFieldSet(_rootOptions, this, options);
56
- }
57
- _superPropGet(OptionsSet, "add", this, 3)([options]);
58
- return this;
59
- }
60
- }, {
61
- key: "apply",
62
- value: function apply(type, thisArgument, argumentsList) {
63
- var returnValue;
64
- var rootOptions = _classPrivateFieldGet(_rootOptions, this);
65
- var _ref = rootOptions || {},
66
- rootEvent = _ref[type];
67
- if (typeof rootEvent === 'function') {
68
- // 最先调用根节点的事件
69
- returnValue = Reflect.apply(rootEvent, thisArgument, argumentsList);
70
- }
71
- var _iterator = _createForOfIteratorHelper(this),
72
- _step;
73
- try {
74
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
75
- var options = _step.value;
76
- if (options === rootOptions) {
77
- continue;
78
- }
79
- var event = options[type];
80
- if (typeof event !== 'function') {
81
- continue;
82
- }
83
- // 非根节点事件,不处理返回值
84
- Reflect.apply(event, thisArgument, argumentsList);
85
- }
86
- } catch (err) {
87
- _iterator.e(err);
88
- } finally {
89
- _iterator.f();
90
- }
91
- return returnValue;
92
- }
93
- }]);
94
- }(/*#__PURE__*/(0, _wrapNativeSuper2["default"])(Set));
@@ -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
- };