@mic-rexjs/usecases-react 2.12.1 → 2.13.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.
- package/README.md +3 -12
- package/dist/index.min.js +1 -1
- package/es/hooks/useContext/index.d.ts +2 -2
- package/es/hooks/useContextualItem/index.js +0 -1
- package/es/hooks/useEntity/index.d.ts +2 -3
- package/es/hooks/useEntity/index.js +19 -72
- package/es/hooks/useFullArguments/types.d.ts +3 -3
- package/es/hooks/useIsRenderingRef/index.d.ts +1 -1
- package/es/hooks/useProvider/index.d.ts +2 -2
- package/es/hooks/useReducers/index.d.ts +6 -0
- package/es/hooks/useReducers/index.js +40 -0
- package/es/hooks/useStatuses/index.d.ts +2 -2
- package/es/hooks/useStatuses/index.js +3 -1
- package/es/hooks/useStore/index.d.ts +6 -0
- package/es/hooks/useStore/index.js +68 -0
- package/es/hooks/useUseCase/index.js +11 -47
- package/es/hooks/useUseCase/index.test.js +222 -107
- package/es/hooks/useUseCase/types.d.ts +3 -4
- package/es/methods/initStore/index.d.ts +3 -0
- package/es/methods/initStore/index.js +23 -0
- package/es/types.d.ts +5 -1
- package/es/usecases/contextUseCase/types.d.ts +12 -12
- package/es/usecases/entityRuntimeUseCase/index.d.ts +2 -0
- package/es/usecases/entityRuntimeUseCase/index.js +16 -0
- package/es/usecases/entityRuntimeUseCase/types.d.ts +8 -0
- package/es/usecases/entityRuntimeUseCase/types.js +1 -0
- package/es/usecases/valueUseCase/index.js +1 -1
- package/lib/hooks/useContextualItem/index.js +0 -1
- package/lib/hooks/useEntity/index.js +19 -73
- package/lib/hooks/useReducers/index.js +50 -0
- package/lib/hooks/useStatuses/index.js +3 -1
- package/lib/hooks/useStore/index.js +75 -0
- package/lib/hooks/useUseCase/index.js +12 -48
- package/lib/hooks/useUseCase/index.test.js +283 -126
- package/lib/methods/initStore/index.js +29 -0
- package/lib/usecases/entityRuntimeUseCase/index.js +25 -0
- package/lib/usecases/entityRuntimeUseCase/types.js +5 -0
- package/lib/usecases/valueUseCase/index.js +1 -1
- package/package.json +3 -3
- package/es/hooks/useRuntimeEntity/index.d.ts +0 -5
- package/es/hooks/useRuntimeEntity/index.js +0 -22
- package/lib/hooks/useRuntimeEntity/index.js +0 -28
package/README.md
CHANGED
|
@@ -52,8 +52,6 @@ const MyComponent = (): React.ReactElement => {
|
|
|
52
52
|
```tsx
|
|
53
53
|
// a.ts
|
|
54
54
|
import {
|
|
55
|
-
objectUseCase,
|
|
56
|
-
ObjectReducers,
|
|
57
55
|
EntityGenerator,
|
|
58
56
|
EntityReducers
|
|
59
57
|
} from '@mic-rexjs/usecases';
|
|
@@ -74,17 +72,10 @@ type FileReducers<T extends File> = EntityReducers<
|
|
|
74
72
|
writeFile(entity: T, content: string): EntityGenerator<T, string>;
|
|
75
73
|
isTxt(entity: T): boolean;
|
|
76
74
|
},
|
|
77
|
-
// optional to extends an existed reducers
|
|
78
|
-
ObjectReducers<T>
|
|
79
75
|
>;
|
|
80
76
|
|
|
81
77
|
const fileUseCase = <T extends File>({ maxContentLength = 2000 }: FileUseCaseOptions = {}): FileReducers<T> => {
|
|
82
|
-
|
|
83
|
-
* if you have not extends an existed reducers,
|
|
84
|
-
* you should call `entityUseCase` at here,
|
|
85
|
-
* such as `const entityReducers = entityUseCase<T>()`.
|
|
86
|
-
*/
|
|
87
|
-
const objectReducers = objectUseCase<T>();
|
|
78
|
+
const entityReducers = entityUseCase<T>();
|
|
88
79
|
|
|
89
80
|
const writeFile = function* (entity: T, content: string): EntityGenerator<T, string> {
|
|
90
81
|
const { content: oldContent } = entity;
|
|
@@ -110,7 +101,7 @@ const fileUseCase = <T extends File>({ maxContentLength = 2000 }: FileUseCaseOpt
|
|
|
110
101
|
return path.endsWith('.txt');
|
|
111
102
|
};
|
|
112
103
|
|
|
113
|
-
return { ...
|
|
104
|
+
return { ...entityReducers, writeFile, isTxt };
|
|
114
105
|
};
|
|
115
106
|
|
|
116
107
|
// b.tsx
|
|
@@ -184,4 +175,4 @@ ReactDOM.render(
|
|
|
184
175
|
```
|
|
185
176
|
|
|
186
177
|
## Test Demos
|
|
187
|
-
- [useUseCase](https://github.com/mic-rexjs/usecases-react/blob/main/src/hooks/useUseCase/index.test.tsx)
|
|
178
|
+
- [useUseCase](https://github.com/mic-rexjs/usecases-react/blob/main/src/hooks/useUseCase/index.test.tsx)
|
package/dist/index.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/*! For license information please see index.min.js.LICENSE.txt */
|
|
2
|
-
(()=>{var t={698(t,e){"use strict";var r=Symbol.for("react.transitional.element");Symbol.for("react.fragment"),e.jsx=function(t,e,n){var o=null;if(void 0!==n&&(o=""+n),void 0!==e.key&&(o=""+e.key),"key"in e)for(var u in n={},e)"key"!==u&&(n[u]=e[u]);else n=e;return e=n.ref,{$$typeof:r,type:t,key:o,ref:void 0!==e?e:null,props:n}}},848(t,e,r){"use strict";t.exports=r(698)},172(t){t.exports=function(t,e){this.v=t,this.k=e},t.exports.__esModule=!0,t.exports.default=t.exports},993(t,e,r){var n=r(546);function o(){var e,r,u="function"==typeof Symbol?Symbol:{},a=u.iterator||"@@iterator",i=u.toStringTag||"@@toStringTag";function c(t,o,u,a){var i=o&&o.prototype instanceof f?o:f,c=Object.create(i.prototype);return n(c,"_invoke",function(t,n,o){var u,a,i,c=0,f=o||[],l=!1,p={p:0,n:0,v:e,a:y,f:y.bind(e,4),d:function(t,r){return u=t,a=0,i=e,p.n=r,s}};function y(t,n){for(a=t,i=n,r=0;!l&&c&&!o&&r<f.length;r++){var o,u=f[r],y=p.p,v=u[2];t>3?(o=v===n)&&(i=u[(a=u[4])?5:(a=3,3)],u[4]=u[5]=e):u[0]<=y&&((o=t<2&&y<u[1])?(a=0,p.v=n,p.n=u[1]):y<v&&(o=t<3||u[0]>n||n>v)&&(u[4]=t,u[5]=n,p.n=v,a=0))}if(o||t>1)return s;throw l=!0,n}return function(o,f,v){if(c>1)throw TypeError("Generator is already running");for(l&&1===f&&y(f,v),a=f,i=v;(r=a<2?e:i)||!l;){u||(a?a<3?(a>1&&(p.n=-1),y(a,i)):p.n=i:p.v=i);try{if(c=2,u){if(a||(o="next"),r=u[o]){if(!(r=r.call(u,i)))throw TypeError("iterator result is not an object");if(!r.done)return r;i=r.value,a<2&&(a=0)}else 1===a&&(r=u.return)&&r.call(u),a<2&&(i=TypeError("The iterator does not provide a '"+o+"' method"),a=1);u=e}else if((r=(l=p.n<0)?i:t.call(n,p))!==s)break}catch(t){u=e,a=1,i=t}finally{c=1}}return{value:r,done:l}}}(t,u,a),!0),c}var s={};function f(){}function l(){}function p(){}r=Object.getPrototypeOf;var y=[][a]?r(r([][a]())):(n(r={},a,function(){return this}),r),v=p.prototype=f.prototype=Object.create(y);function d(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,n(t,i,"GeneratorFunction")),t.prototype=Object.create(v),t}return l.prototype=p,n(v,"constructor",p),n(p,"constructor",l),l.displayName="GeneratorFunction",n(p,i,"GeneratorFunction"),n(v),n(v,i,"Generator"),n(v,a,function(){return this}),n(v,"toString",function(){return"[object Generator]"}),(t.exports=o=function(){return{w:c,m:d}},t.exports.__esModule=!0,t.exports.default=t.exports)()}t.exports=o,t.exports.__esModule=!0,t.exports.default=t.exports},869(t,e,r){var n=r(887);t.exports=function(t,e,r,o,u){var a=n(t,e,r,o,u);return a.next().then(function(t){return t.done?t.value:a.next()})},t.exports.__esModule=!0,t.exports.default=t.exports},887(t,e,r){var n=r(993),o=r(791);t.exports=function(t,e,r,u,a){return new o(n().w(t,e,r,u),a||Promise)},t.exports.__esModule=!0,t.exports.default=t.exports},791(t,e,r){var n=r(172),o=r(546);t.exports=function t(e,r){function u(t,o,a,i){try{var c=e[t](o),s=c.value;return s instanceof n?r.resolve(s.v).then(function(t){u("next",t,a,i)},function(t){u("throw",t,a,i)}):r.resolve(s).then(function(t){c.value=t,a(c)},function(t){return u("throw",t,a,i)})}catch(t){i(t)}}var a;this.next||(o(t.prototype),o(t.prototype,"function"==typeof Symbol&&Symbol.asyncIterator||"@asyncIterator",function(){return this})),o(this,"_invoke",function(t,e,n){function o(){return new r(function(e,r){u(t,n,e,r)})}return a=a?a.then(o,o):o()},!0)},t.exports.__esModule=!0,t.exports.default=t.exports},546(t){function e(r,n,o,u){var a=Object.defineProperty;try{a({},"",{})}catch(r){a=0}t.exports=e=function(t,r,n,o){function u(r,n){e(t,r,function(t){return this._invoke(r,n,t)})}r?a?a(t,r,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[r]=n:(u("next",0),u("throw",1),u("return",2))},t.exports.__esModule=!0,t.exports.default=t.exports,e(r,n,o,u)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports},373(t){t.exports=function(t){var e=Object(t),r=[];for(var n in e)r.unshift(n);return function t(){for(;r.length;)if((n=r.pop())in e)return t.value=n,t.done=!1,t;return t.done=!0,t}},t.exports.__esModule=!0,t.exports.default=t.exports},633(t,e,r){var n=r(172),o=r(993),u=r(869),a=r(887),i=r(791),c=r(373),s=r(579);function f(){"use strict";var e=o(),r=e.m(f),l=(Object.getPrototypeOf?Object.getPrototypeOf(r):r.__proto__).constructor;function p(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))}var y={throw:1,return:2,break:3,continue:3};function v(t){var e,r;return function(n){e||(e={stop:function(){return r(n.a,2)},catch:function(){return n.v},abrupt:function(t,e){return r(n.a,y[t],e)},delegateYield:function(t,o,u){return e.resultName=o,r(n.d,s(t),u)},finish:function(t){return r(n.f,t)}},r=function(t,r,o){n.p=e.prev,n.n=e.next;try{return t(r,o)}finally{e.next=n.n}}),e.resultName&&(e[e.resultName]=n.v,e.resultName=void 0),e.sent=n.v,e.next=n.n;try{return t.call(this,e)}finally{n.p=e.prev,n.n=e.next}}}return(t.exports=f=function(){return{wrap:function(t,r,n,o){return e.w(v(t),r,n,o&&o.reverse())},isGeneratorFunction:p,mark:e.m,awrap:function(t,e){return new n(t,e)},AsyncIterator:i,async:function(t,e,r,n,o){return(p(e)?a:u)(v(t),e,r,n,o)},keys:c,values:s}},t.exports.__esModule=!0,t.exports.default=t.exports)()}t.exports=f,t.exports.__esModule=!0,t.exports.default=t.exports},579(t,e,r){var n=r(738).default;t.exports=function(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],r=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}throw new TypeError(n(t)+" is not iterable")},t.exports.__esModule=!0,t.exports.default=t.exports},738(t){function e(r){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports},756(t,e,r){var n=r(633)();t.exports=n;try{regeneratorRuntime=n}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var u=e[n]={exports:{}};return t[n](u,u.exports,r),u.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};(()=>{"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function o(t,e){if(null==t)return{};var r,n,o=function(t,e){if(null==t)return{};var r={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(-1!==e.indexOf(n))continue;r[n]=t[n]}return r}(t,e);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(t);for(n=0;n<u.length;n++)r=u[n],-1===e.indexOf(r)&&{}.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}r.r(n),r.d(n,{UseCaseFragment:()=>D,useUseCase:()=>V});var u=r(848);function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function i(t,e){if(t){if("string"==typeof t)return a(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(t,e):void 0}}function c(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}function s(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,u,a,i=[],c=!0,s=!1;try{if(u=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=u.call(r)).done)&&(i.push(n.value),i.length!==e);c=!0);}catch(t){s=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return i}}(t,e)||i(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}const f=React;var l,p=r.n(f),y=function(t){return s((0,f.useState)(t),1)[0]};!function(t){t[t.None=0]="None",t[t.Entity=2]="Entity"}(l||(l={}));var v=function(t){return s((0,f.useState)(function(){return t}),1)[0]},d=function(t,e){return y(function(){return t(e)})};const b=ahooks,h=usecases;var m;!function(t){t[t.None=0]="None",t[t.RootEnabled=2]="RootEnabled",t[t.ContextEnabled=4]="ContextEnabled",t[t.EntityEnabled=8]="EntityEnabled",t[t.ContextRootEnabled=6]="ContextRootEnabled",t[t.EntityRootEnabled=14]="EntityRootEnabled"}(m||(m={}));var x=(0,h.createUseCase)(function(){var t=new Map,e=(0,f.createContext)(null);return function(){return{createContextValue:function(t,e,r){return(r&m.EntityEnabled)===m.EntityEnabled?{store:t,reducers:e,statuses:r}:{reducers:e,statuses:r}},getUseCaseContext:function(r){return t.has(r)?t.get(r).value:e},registerUseCase:function(r,n){if(t.has(r)){var o=t.get(r),u=o.value,a=o.times;return t.set(r,{value:u,times:a+1}),u}if((n&l.Entity)!==l.Entity)return e;var i=(0,f.createContext)(null);return t.set(r,{value:i,times:1}),i},unregisterUseCase:function(e,r){if((r&l.Entity)!==l.Entity)return!1;if(!t.has(e))return!1;var n=t.get(e),o=n.value,u=n.times;return 1===u?t.delete(e):t.set(e,{value:o,times:u-1}),!0}}}}),g=function(t,e,r){return y(function(){return(0,h.createEntityReducers)(t,e,r)})},O=r(756),E=r.n(O);function w(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function j(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?w(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):w(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var C=(0,h.createUseCase)(function(){return function(){var e=(0,h.utilsUseCase)().createKey,r=e(),n=(0,h.entityUseCase)(),o=function(e,r){return"object"===t(e)&&null!==e&&Object.hasOwn(e,r)},u=function(t,e){return t!==e},a=function(e,r,n){if(e===r)return!0;var o="object"===t(e)&&null!==e,u="object"===t(r)&&null!==r;if(!o||!u)return!1;for(var a=!0,i=Object.keys(e),c=Object.keys(r),s=i.length,f=[].concat(i,c),l="function"==typeof n,p=0,y=f.length;p<y;p++){var v=f[p],d=p>=s,b=i.includes(v);if(!d||!b){var h=Object.hasOwn(e,v),m=Object.hasOwn(r,v),x=h&&!m||!h&&m,g=e[v],O=r[v];if(x||g!==O){if(a=!1,!l)break;n(v,O,g)}}}return a},i=E().mark(function t(e,r){return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(u(e,r)){t.next=1;break}return t.abrupt("return",!1);case 1:return t.next=2,r;case 2:return t.abrupt("return",!0);case 3:case"end":return t.stop()}},t)}),f=E().mark(function t(e,r){var n,o,u,i,c,s;return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=Array.isArray(e),o=Array.isArray(r),i=(u=n&&o)?[]:{},u&&(c=e.length,s=r.length,i.length=Math.max(c,s)),a(e,r,function(t,e){i[t]=e})){t.next=1;break}return t.next=1,r;case 1:return t.abrupt("return",i);case 2:case"end":return t.stop()}},t)}),l=E().mark(function t(e,r){return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!a(e,r)){t.next=1;break}return t.abrupt("return",!0);case 1:return t.next=2,r;case 2:return t.abrupt("return",!1);case 3:case"end":return t.stop()}},t)}),p=E().mark(function t(n,o,u){return E().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(l(n,o),"t0",1);case 1:return t.t0||(r=null!=u?u:e()),t.abrupt("return",r);case 2:case"end":return t.stop()}},t)});return j(j({},n),{},{isValueChanged:u,isValueMatched:a,matchProperty:function(t,e,r,n){var u=!0,a=r,i=[{fieldPaths:[],newEntity:e,newValue:e,oldEntity:t,oldValue:t}];do{var f=i.shift(),l=f.oldValue,p=f.newValue,y=f.fieldPaths,v=s(a.match(/^([^.]+)\.(.+)$/)||[],3),d=v[1],b=void 0===d?a:d,h=v[2],m=void 0===h?"":h,x=o(l,b),g=o(p,b);if(x||g){var O=x?l[b]:void 0,E=g?p[b]:void 0,w={fieldPaths:[].concat(c(y),[b]),newEntity:e,newValue:E,oldEntity:t,oldValue:O};if(m){a=m,i.push(w);continue}if(O===E)continue;u=!1,null==n||n(w)}else if(!/^\d+^/.test(b))for(var j=Array.isArray(l)?l:[],C=Array.isArray(p)?p:[],S=j.length,P=C.length,_=Math.max(S,P),M=0;M<_;M++)i.push({fieldPaths:[].concat(c(y),["".concat(M)]),newEntity:e,newValue:C[M],oldEntity:t,oldValue:j[M]})}while(i.length>0);return u},recordValue:i,recordValueDiff:f,recordValueMatch:l,recordValueMatchWith:p})}}),S=function(){var t=C().isValueMatched,e=function(e,r){var n,o=r||{},u=o.onShouldCache,a=void 0===u?function(){return!0}:u,i=o.onCompare,c=void 0===i?function(e,r){return t(e,r)}:i;return function(){for(var t=a(),r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];if(n&&t){var i=n,s=i.parameters,f=i.returnValue;if(c(s,o))return f}var l=e.apply(void 0,o);return t&&(n={parameters:o,returnValue:l}),l}};return{cacheCall:e,cacheCalls:function(t,r){var n={};return Object.entries(t).forEach(function(t){var o=s(t,2),u=o[0],a=o[1];n[u]=e(a,r)}),n},captureCalls:function(t,e){var r={};return Object.keys(t).forEach(function(n){var o=t[n];r[n]="function"!=typeof o?o:function(){for(var t=arguments.length,r=new Array(t),o=0;o<t;o++)r[o]=arguments[o];return e(n,r)}}),r}}},P=function(t,e,r){var n,o=s((0,g(n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],C).recordValueMatchWith)(n),2)[1],u=(0,b.useLatest)(r),a=d(S).cacheCall,i=(0,b.useMemoizedFn)(function(){var t=u.current;return a(t,{onCompare:function(){return!0}})}),c=(0,b.useCreation)(function(){return i()},[o,i]);return(0,b.useCreation)(function(){return(e&m.RootEnabled)!==m.RootEnabled&&t?t:c()},[e,t,c])};function _(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function M(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?_(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):_(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var k=["watch","onChange","options"],V=function(){for(var e,r=(e=(0,b.useLatest)(!0),(0,f.useEffect)(function(){e.current=!1}),e),n=arguments.length,u=new Array(n),a=0;a<n;a++)u[a]=arguments[a];var i=function(e){return y(function(){return"function"===t(s(e,2)[1])?l.Entity:l.None})}(u),O=function(t,e){var r=s(t,4),n=r[0],o=r[1],u=r[2],a=r[3];return(e&l.Entity)!==l.Entity?[null,n,o||{},u||[]]:[n,o,u||{},a||[]]}(u,i),E=s(O,4),w=E[0],j=E[1],_=E[2],V=E[3],A=v(j),R=A,N=A,U=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:l.None,r=y(function(){return(0,x().registerUseCase)(t,e)});return(0,b.useUnmount)(function(){(0,x().unregisterUseCase)(t,e)}),r}(A,i),D=(0,f.useContext)(U),T=D,F=function(t,e){return(0,b.useCreation)(function(){var r=m.None,n=(e||{}).store;return(t&l.Entity)===l.Entity&&(r|=m.EntityRootEnabled),r|=e?m.ContextEnabled:m.RootEnabled,n&&(r|=m.EntityEnabled),r},[t,e])}(i,D),G=(0,b.useLatest)(_),I=(D||{}).reducers,L=void 0===I?null:I,$=(T||{}).store,z=s(function(t,e,r,n,o){var u=(0,b.useUpdate)(),a=(0,f.useRef)(null),i=(0,b.useLatest)(n),c=r?r.value:null,l=(t&m.EntityEnabled)===m.EntityEnabled,p=(t&m.EntityRootEnabled)===m.EntityRootEnabled,y=g(o,C).recordValueDiff,v=P(r,t,function(){var t;if(p){var r="function"==typeof e,n=(a.current||{}).value,u=s(y(o),2)[1],i=r?e(n,u):e;t=new h.EntityStore(i)}else t=new h.EntityStore(null);return a.current=t,t},o),d=function(t,e,r,n){var o=g(e,C),u=o.isValueChanged,a=o.recordValue,i=u(e);if((n&m.EntityRootEnabled)!==m.EntityRootEnabled)return r;var c="function"==typeof e,s=t.value;switch(!0){case c:case!i:return s}return a(e),e}(v,e,c,t),x=(0,b.useMemoizedFn)(function(t,e){var r=i.current,n=r.onChange,o=r.watch;o&&function(t,e,r){for(var n,o=C().matchProperty,u=function(){var t=i[a],u=(n=s(t,2))[0],c=n[1];o(r,e,u,function(t){c(t)})},a=0,i=Object.entries(t);a<i.length;a++)u()}(o,t,e),null==n||n(t,e),p&&u()});return p&&v.setValue(d,!0),(0,b.useCreation)(function(){l&&v.watch(x)},[l,v,x]),(0,f.useEffect)(function(){return function(){v.unwatch(x)}},[l,v,x]),(0,b.useCreation)(function(){return[d,v]},[d,v])}(F,w,void 0===$?null:$,_,V),2),W=z[0],Y=z[1],K=d(S),q=K.cacheCalls,B=K.captureCalls,H=P(L,F,function(){var t=B(_,function(t,e){var r,n,o;return null===(n=(o=G.current)[t])||void 0===n?void 0:(r=n).call.apply(r,[o].concat(c(e)))});if((F&m.EntityEnabled)!==m.EntityEnabled)return R(t);var e=t,r=(e.watch,e.onChange,e.options),n=o(e,k);return(0,h.createEntityReducers)(Y,N,M(M(M({},n),r),{},{onGenerate:function(t,e){return e}}))},V),J=function(t,e,r,n){var o=r.value,u=(0,b.useCreation)(function(){return(0,x().createContextValue)(r,n,t)},[t,o,r,n]),a=(0,b.useLatest)(u);return v(function(t){var r=t.children,n=t.with,o=void 0===n?[]:n,u=e.Provider,i=a.current;return p().createElement(u,{value:i},o.reduceRight(function(t,e){return p().createElement(e,{},t)},r))})}(F,U,Y,H);return(0,b.useCreation)(function(){if((F&m.EntityEnabled)!==m.EntityEnabled)return H;var e=q(H,{onShouldCache:function(){return r.current}}),n=null===W,o=Array.isArray(W);return["object"!==t(W)||n||o?W:M({},W),e,J]},[F,W,H,J,r,q])},A=function(t){var e=t.usecase,r=t.watch,n=t.onMount,o=t.onChange,a=s(V(e,{watch:r,onChange:o}),1)[0];return(0,b.useMount)(function(){null==n||n(a)}),(0,u.jsx)(f.Fragment,{})};function R(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function N(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?R(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):R(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var U=["usecase"],D=function(t){var e=t.usecase,r=o(t,U),n=(0,V(x).getUseCaseContext)(e),a=(0,f.useContext)(n);return(0,u.jsx)(f.Fragment,{children:null===a?null:(0,u.jsx)(A,N({usecase:e},r))})}})();var o=usecases="undefined"==typeof usecases?{}:usecases;for(var u in n)o[u]=n[u];n.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})})();
|
|
2
|
+
(()=>{var t={698(t,e){"use strict";var r=Symbol.for("react.transitional.element");Symbol.for("react.fragment"),e.jsx=function(t,e,n){var o=null;if(void 0!==n&&(o=""+n),void 0!==e.key&&(o=""+e.key),"key"in e)for(var u in n={},e)"key"!==u&&(n[u]=e[u]);else n=e;return e=n.ref,{$$typeof:r,type:t,key:o,ref:void 0!==e?e:null,props:n}}},848(t,e,r){"use strict";t.exports=r(698)},172(t){t.exports=function(t,e){this.v=t,this.k=e},t.exports.__esModule=!0,t.exports.default=t.exports},993(t,e,r){var n=r(546);function o(){var e,r,u="function"==typeof Symbol?Symbol:{},a=u.iterator||"@@iterator",i=u.toStringTag||"@@toStringTag";function c(t,o,u,a){var i=o&&o.prototype instanceof f?o:f,c=Object.create(i.prototype);return n(c,"_invoke",function(t,n,o){var u,a,i,c=0,f=o||[],l=!1,p={p:0,n:0,v:e,a:y,f:y.bind(e,4),d:function(t,r){return u=t,a=0,i=e,p.n=r,s}};function y(t,n){for(a=t,i=n,r=0;!l&&c&&!o&&r<f.length;r++){var o,u=f[r],y=p.p,b=u[2];t>3?(o=b===n)&&(i=u[(a=u[4])?5:(a=3,3)],u[4]=u[5]=e):u[0]<=y&&((o=t<2&&y<u[1])?(a=0,p.v=n,p.n=u[1]):y<b&&(o=t<3||u[0]>n||n>b)&&(u[4]=t,u[5]=n,p.n=b,a=0))}if(o||t>1)return s;throw l=!0,n}return function(o,f,b){if(c>1)throw TypeError("Generator is already running");for(l&&1===f&&y(f,b),a=f,i=b;(r=a<2?e:i)||!l;){u||(a?a<3?(a>1&&(p.n=-1),y(a,i)):p.n=i:p.v=i);try{if(c=2,u){if(a||(o="next"),r=u[o]){if(!(r=r.call(u,i)))throw TypeError("iterator result is not an object");if(!r.done)return r;i=r.value,a<2&&(a=0)}else 1===a&&(r=u.return)&&r.call(u),a<2&&(i=TypeError("The iterator does not provide a '"+o+"' method"),a=1);u=e}else if((r=(l=p.n<0)?i:t.call(n,p))!==s)break}catch(t){u=e,a=1,i=t}finally{c=1}}return{value:r,done:l}}}(t,u,a),!0),c}var s={};function f(){}function l(){}function p(){}r=Object.getPrototypeOf;var y=[][a]?r(r([][a]())):(n(r={},a,function(){return this}),r),b=p.prototype=f.prototype=Object.create(y);function v(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,n(t,i,"GeneratorFunction")),t.prototype=Object.create(b),t}return l.prototype=p,n(b,"constructor",p),n(p,"constructor",l),l.displayName="GeneratorFunction",n(p,i,"GeneratorFunction"),n(b),n(b,i,"Generator"),n(b,a,function(){return this}),n(b,"toString",function(){return"[object Generator]"}),(t.exports=o=function(){return{w:c,m:v}},t.exports.__esModule=!0,t.exports.default=t.exports)()}t.exports=o,t.exports.__esModule=!0,t.exports.default=t.exports},869(t,e,r){var n=r(887);t.exports=function(t,e,r,o,u){var a=n(t,e,r,o,u);return a.next().then(function(t){return t.done?t.value:a.next()})},t.exports.__esModule=!0,t.exports.default=t.exports},887(t,e,r){var n=r(993),o=r(791);t.exports=function(t,e,r,u,a){return new o(n().w(t,e,r,u),a||Promise)},t.exports.__esModule=!0,t.exports.default=t.exports},791(t,e,r){var n=r(172),o=r(546);t.exports=function t(e,r){function u(t,o,a,i){try{var c=e[t](o),s=c.value;return s instanceof n?r.resolve(s.v).then(function(t){u("next",t,a,i)},function(t){u("throw",t,a,i)}):r.resolve(s).then(function(t){c.value=t,a(c)},function(t){return u("throw",t,a,i)})}catch(t){i(t)}}var a;this.next||(o(t.prototype),o(t.prototype,"function"==typeof Symbol&&Symbol.asyncIterator||"@asyncIterator",function(){return this})),o(this,"_invoke",function(t,e,n){function o(){return new r(function(e,r){u(t,n,e,r)})}return a=a?a.then(o,o):o()},!0)},t.exports.__esModule=!0,t.exports.default=t.exports},546(t){function e(r,n,o,u){var a=Object.defineProperty;try{a({},"",{})}catch(r){a=0}t.exports=e=function(t,r,n,o){function u(r,n){e(t,r,function(t){return this._invoke(r,n,t)})}r?a?a(t,r,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[r]=n:(u("next",0),u("throw",1),u("return",2))},t.exports.__esModule=!0,t.exports.default=t.exports,e(r,n,o,u)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports},373(t){t.exports=function(t){var e=Object(t),r=[];for(var n in e)r.unshift(n);return function t(){for(;r.length;)if((n=r.pop())in e)return t.value=n,t.done=!1,t;return t.done=!0,t}},t.exports.__esModule=!0,t.exports.default=t.exports},633(t,e,r){var n=r(172),o=r(993),u=r(869),a=r(887),i=r(791),c=r(373),s=r(579);function f(){"use strict";var e=o(),r=e.m(f),l=(Object.getPrototypeOf?Object.getPrototypeOf(r):r.__proto__).constructor;function p(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))}var y={throw:1,return:2,break:3,continue:3};function b(t){var e,r;return function(n){e||(e={stop:function(){return r(n.a,2)},catch:function(){return n.v},abrupt:function(t,e){return r(n.a,y[t],e)},delegateYield:function(t,o,u){return e.resultName=o,r(n.d,s(t),u)},finish:function(t){return r(n.f,t)}},r=function(t,r,o){n.p=e.prev,n.n=e.next;try{return t(r,o)}finally{e.next=n.n}}),e.resultName&&(e[e.resultName]=n.v,e.resultName=void 0),e.sent=n.v,e.next=n.n;try{return t.call(this,e)}finally{n.p=e.prev,n.n=e.next}}}return(t.exports=f=function(){return{wrap:function(t,r,n,o){return e.w(b(t),r,n,o&&o.reverse())},isGeneratorFunction:p,mark:e.m,awrap:function(t,e){return new n(t,e)},AsyncIterator:i,async:function(t,e,r,n,o){return(p(e)?a:u)(b(t),e,r,n,o)},keys:c,values:s}},t.exports.__esModule=!0,t.exports.default=t.exports)()}t.exports=f,t.exports.__esModule=!0,t.exports.default=t.exports},579(t,e,r){var n=r(738).default;t.exports=function(t){if(null!=t){var e=t["function"==typeof Symbol&&Symbol.iterator||"@@iterator"],r=0;if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length))return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}}}throw new TypeError(n(t)+" is not iterable")},t.exports.__esModule=!0,t.exports.default=t.exports},738(t){function e(r){return t.exports=e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.__esModule=!0,t.exports.default=t.exports,e(r)}t.exports=e,t.exports.__esModule=!0,t.exports.default=t.exports},756(t,e,r){var n=r(633)();t.exports=n;try{regeneratorRuntime=n}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=n:Function("r","regeneratorRuntime = r")(n)}}},e={};function r(n){var o=e[n];if(void 0!==o)return o.exports;var u=e[n]={exports:{}};return t[n](u,u.exports,r),u.exports}r.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return r.d(e,{a:e}),e},r.d=(t,e)=>{for(var n in e)r.o(e,n)&&!r.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},r.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var n={};(()=>{"use strict";function t(e){return t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t(e)}function e(e,r,n){return(r=function(e){var r=function(e){if("object"!=t(e)||!e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,"string");if("object"!=t(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(e)}(e);return"symbol"==t(r)?r:r+""}(r))in e?Object.defineProperty(e,r,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[r]=n,e}function o(t,e){if(null==t)return{};var r,n,o=function(t,e){if(null==t)return{};var r={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(-1!==e.indexOf(n))continue;r[n]=t[n]}return r}(t,e);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(t);for(n=0;n<u.length;n++)r=u[n],-1===e.indexOf(r)&&{}.propertyIsEnumerable.call(t,r)&&(o[r]=t[r])}return o}r.r(n),r.d(n,{UseCaseFragment:()=>G,useUseCase:()=>U});var u=r(848);function a(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function i(t,e){if(t){if("string"==typeof t)return a(t,e);var r={}.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?a(t,e):void 0}}function c(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var r=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=r){var n,o,u,a,i=[],c=!0,s=!1;try{if(u=(r=r.call(t)).next,0===e){if(Object(r)!==r)return;c=!1}else for(;!(c=(n=u.call(r)).done)&&(i.push(n.value),i.length!==e);c=!0);}catch(t){s=!0,o=t}finally{try{if(!c&&null!=r.return&&(a=r.return(),Object(a)!==a))return}finally{if(s)throw o}}return i}}(t,e)||i(t,e)||function(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}const s=React;var f,l=r.n(s),p=function(t){return c((0,s.useState)(t),1)[0]};!function(t){t[t.None=0]="None",t[t.Entity=2]="Entity"}(f||(f={}));var y=function(t){return c((0,s.useState)(function(){return t}),1)[0]},b=function(t,e){return p(function(){return t(e)})};const v=ahooks,d=usecases;var h;!function(t){t[t.None=0]="None",t[t.RootEnabled=2]="RootEnabled",t[t.ContextEnabled=4]="ContextEnabled",t[t.EntityEnabled=8]="EntityEnabled",t[t.ContextRootEnabled=6]="ContextRootEnabled",t[t.EntityRootEnabled=14]="EntityRootEnabled"}(h||(h={}));var O=(0,d.createUseCase)(function(){var t=new Map,e=(0,s.createContext)(null);return function(){return{createContextValue:function(t,e,r){return(r&h.EntityEnabled)===h.EntityEnabled?{store:t,reducers:e,statuses:r}:{reducers:e,statuses:r}},getUseCaseContext:function(r){return t.has(r)?t.get(r).value:e},registerUseCase:function(r,n){if(t.has(r)){var o=t.get(r),u=o.value,a=o.times;return t.set(r,{value:u,times:a+1}),u}if((n&f.Entity)!==f.Entity)return e;var i=(0,s.createContext)(null);return t.set(r,{value:i,times:1}),i},unregisterUseCase:function(e,r){if((r&f.Entity)!==f.Entity)return!1;if(!t.has(e))return!1;var n=t.get(e),o=n.value,u=n.times;return 1===u?t.delete(e):t.set(e,{value:o,times:u-1}),!0}}}}),m=function(t,e,r){return p(function(){return(0,d.createEntityReducers)(t,e,r)})};function g(t){return function(t){if(Array.isArray(t))return a(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||i(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}()}var x=r(756),j=r.n(x);function w(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function E(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?w(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):w(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var P=(0,d.createUseCase)(function(){return function(){var e=(0,d.entityUseCase)(),r=(0,d.utilsUseCase)().createKey,n=r(),o=function(e,r){return"object"===t(e)&&null!==e&&Object.hasOwn(e,r)},u=function(t,e){return t!==e},a=function(e,r,n){if(e===r)return!0;var o="object"===t(e)&&null!==e,u="object"===t(r)&&null!==r;if(!o||!u)return!1;for(var a=!0,i=Object.keys(e),c=Object.keys(r),s=i.length,f=[].concat(i,c),l="function"==typeof n,p=0,y=f.length;p<y;p++){var b=f[p],v=p>=s,d=i.includes(b);if(!v||!d){var h=Object.hasOwn(e,b),O=Object.hasOwn(r,b),m=h&&!O||!h&&O,g=e[b],x=r[b];if(m||g!==x){if(a=!1,!l)break;n(b,x,g)}}}return a},i=j().mark(function t(e,r){return j().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(u(e,r)){t.next=1;break}return t.abrupt("return",!1);case 1:return t.next=2,r;case 2:return t.abrupt("return",!0);case 3:case"end":return t.stop()}},t)}),s=j().mark(function t(e,r){var n,o,u,i,c,s;return j().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(n=Array.isArray(e),o=Array.isArray(r),i=(u=n&&o)?[]:{},u&&(c=e.length,s=r.length,i.length=Math.max(c,s)),a(e,r,function(t,e){i[t]=e})){t.next=1;break}return t.next=1,r;case 1:return t.abrupt("return",i);case 2:case"end":return t.stop()}},t)}),f=j().mark(function t(e,r){return j().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(!a(e,r)){t.next=1;break}return t.abrupt("return",!0);case 1:return t.next=2,r;case 2:return t.abrupt("return",!1);case 3:case"end":return t.stop()}},t)}),l=j().mark(function t(e,o,u){return j().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.delegateYield(f(e,o),"t0",1);case 1:return t.t0||(n=null!=u?u:r()),t.abrupt("return",n);case 2:case"end":return t.stop()}},t)});return E(E({},e),{},{isValueChanged:u,isValueMatched:a,matchProperty:function(t,e,r,n){var u=!0,a=r,i=[{fieldPaths:[],newEntity:e,newValue:e,oldEntity:t,oldValue:t}];do{var s=i.shift(),f=s.oldValue,l=s.newValue,p=s.fieldPaths,y=c(a.match(/^([^.]+)\.(.+)$/)||[],3),b=y[1],v=void 0===b?a:b,d=y[2],h=void 0===d?"":d,O=o(f,v),m=o(l,v);if(O||m){var x=O?f[v]:void 0,j=m?l[v]:void 0,w={fieldPaths:[].concat(g(p),[v]),newEntity:e,newValue:j,oldEntity:t,oldValue:x};if(h){a=h,i.push(w);continue}if(x===j)continue;u=!1,null==n||n(w)}else if(!/^\d+^/.test(v))for(var E=Array.isArray(f)?f:[],P=Array.isArray(l)?l:[],S=E.length,C=P.length,_=Math.max(S,C),M=0;M<_;M++)i.push({fieldPaths:[].concat(g(p),["".concat(M)]),newEntity:e,newValue:P[M],oldEntity:t,oldValue:E[M]})}while(i.length>0);return u},recordValue:i,recordValueDiff:s,recordValueMatch:f,recordValueMatchWith:l})}}),S=function(){var t=P().isValueMatched,e=function(e,r){var n,o=r||{},u=o.onShouldCache,a=void 0===u?function(){return!0}:u,i=o.onCompare,c=void 0===i?function(e,r){return t(e,r)}:i;return function(){for(var t=a(),r=arguments.length,o=new Array(r),u=0;u<r;u++)o[u]=arguments[u];if(n&&t){var i=n,s=i.parameters,f=i.returnValue;if(c(s,o))return f}var l=e.apply(void 0,o);return t&&(n={parameters:o,returnValue:l}),l}};return{cacheCall:e,cacheCalls:function(t,r){var n={};return Object.entries(t).forEach(function(t){var o=c(t,2),u=o[0],a=o[1];n[u]=e(a,r)}),n},captureCalls:function(t,e){var r={};return Object.keys(t).forEach(function(n){var o=t[n];r[n]="function"!=typeof o?o:function(){for(var t=arguments.length,r=new Array(t),o=0;o<t;o++)r[o]=arguments[o];return e(n,r)}}),r}}},C=function(t,e,r){var n,o=c((0,m(n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],P).recordValueMatchWith)(n),2)[1],u=(0,v.useLatest)(r),a=b(S).cacheCall,i=(0,v.useMemoizedFn)(function(){var t=u.current;return a(t,{onCompare:function(){return!0}})}),s=(0,v.useCreation)(function(){return i()},[o,i]);return(0,v.useCreation)(function(){return(e&h.RootEnabled)!==h.RootEnabled&&t?t:s()},[e,t,s])};function _(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function M(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?_(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):_(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var k=["watch","onChange","options"];function V(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function R(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?V(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):V(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var A=function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=(0,d.entityUseCase)(),r=t.onInit;return R(R({},e),{},{initEntity:function(t){return"function"!=typeof r?t:r(t)}})};function D(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}var U=function(){for(var r,n=(r=(0,v.useLatest)(!0),(0,s.useEffect)(function(){r.current=!1}),r),u=arguments.length,a=new Array(u),i=0;i<u;i++)a[i]=arguments[i];var x=function(e){return p(function(){return"function"===t(c(e,2)[1])?f.Entity:f.None})}(a),j=function(t,e){var r=c(t,4),n=r[0],o=r[1],u=r[2],a=r[3];return(e&f.Entity)!==f.Entity?[null,n,o||{},u||[]]:[n,o,u||{},a||[]]}(a,x),w=c(j,4),E=w[0],_=w[1],V=w[2],R=w[3],U=b(S).cacheCalls,N=y(_),T=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f.None,r=p(function(){return(0,O().registerUseCase)(t,e)});return(0,v.useUnmount)(function(){(0,O().unregisterUseCase)(t,e)}),r}(N,x),F=T,I=function(t,e){var r=(0,s.useContext)(t);return(0,v.useCreation)(function(){var t=h.None,n=(r||{}).store;return(e&f.Entity)===f.Entity&&(t|=h.EntityRootEnabled),t|=r?h.ContextEnabled:h.RootEnabled,n&&(t|=h.EntityEnabled),t},[e,r])}(T,x),G=function(t,e,r,n){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],u=(0,v.useUpdate)(),a=(0,v.useLatest)(n),i=(0,s.useRef)(null),f=(r&h.EntityEnabled)===h.EntityEnabled,l=(r&h.EntityRootEnabled)===h.EntityRootEnabled,p=((0,s.useContext)(t)||{}).store,y=void 0===p?null:p,b=m(o,P).recordValueDiff,O=C(y,r,function(){if(!l)return new d.EntityStore(null);var t=i.current,r=c(b(o),2)[1],n=function(t,e,r){if("function"!=typeof t)return new d.EntityStore(t);var n=(e||{}).value,o=new d.EntityStore(n);return(0,(0,d.createEntityReducers)(o,A,{onInit:function(e){return t(e,r)},onReturn:function(t){return o.setValue(t),t}}).initEntity)(),o}(e,t,r);return i.current=n,n},o),g=(0,v.useMemoizedFn)(function(t,e){var r=a.current,n=r.onChange,o=r.watch;o&&function(t,e,r){for(var n,o=P().matchProperty,u=function(){var t=i[a],u=(n=c(t,2))[0],s=n[1];o(r,e,u,function(t){s(t)})},a=0,i=Object.entries(t);a<i.length;a++)u()}(o,t,e),null==n||n(t,e),l&&u()});return(0,v.useCreation)(function(){f&&O.watch(g)},[f,O,g]),(0,s.useEffect)(function(){return function(){O.unwatch(g)}},[f,O,g]),O}(F,E,I,V,R),L=function(t,e,r){var n=m(e,P),o=n.isValueChanged,u=n.recordValue,a=o(e),i=(r&h.EntityRootEnabled)!==h.EntityRootEnabled,c="function"==typeof e,s=t.value;switch(!0){case i:case c:case!a:return s}return u(e),t.disableWatchers(),t.setValue(e),t.enableWatchers(),e}(G,E,I),W=function(t,e,r,n,u){var a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:[],i=(0,v.useLatest)(u),c=((0,s.useContext)(e)||{}).reducers,f=void 0===c?null:c,l=b(S).captureCalls;return C(f,n,function(){var e=l(u,function(t,e){var r,n,o;return null===(n=(o=i.current)[t])||void 0===n?void 0:(r=n).call.apply(r,[o].concat(g(e)))});if((n&h.EntityEnabled)!==h.EntityEnabled)return t(e);var a=e,c=(a.watch,a.onChange,a.options),s=o(a,k);return(0,d.createEntityReducers)(r,t,M(M(M({},s),c),{},{onGenerate:function(t,e){return e}}))},a)}(N,T,G,I,V,R),$=function(t,e,r,n){var o=r.value,u=(0,v.useCreation)(function(){return(0,O().createContextValue)(r,n,t)},[t,o,r,n]),a=(0,v.useLatest)(u);return y(function(t){var r=t.children,n=t.with,o=void 0===n?[]:n,u=e.Provider,i=a.current;return l().createElement(u,{value:i},o.reduceRight(function(t,e){return l().createElement(e,{},t)},r))})}(I,T,G,W);return(0,v.useCreation)(function(){if((I&h.EntityEnabled)!==h.EntityEnabled)return W;var r=U(W,{onShouldCache:function(){return n.current}}),o=null===L,u=Array.isArray(L),a="object"!==t(L)||o||u?L:function(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?D(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):D(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}({},L);return[a,r,$]},[I,L,W,$,n,U])},N=function(t){var e=t.usecase,r=t.watch,n=t.onMount,o=t.onChange,a=c(U(e,{watch:r,onChange:o}),1)[0];return(0,v.useMount)(function(){null==n||n(a)}),(0,u.jsx)(s.Fragment,{})};function T(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,n)}return r}function F(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?T(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):T(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var I=["usecase"],G=function(t){var e=t.usecase,r=o(t,I),n=(0,U(O).getUseCaseContext)(e),a=(0,s.useContext)(n);return(0,u.jsx)(s.Fragment,{children:null===a?null:(0,u.jsx)(N,F({usecase:e},r))})}})();var o=usecases="undefined"==typeof usecases?{}:usecases;for(var u in n)o[u]=n[u];n.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})})();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { UseCase } from '@mic-rexjs/usecases';
|
|
2
2
|
import { ReducerMap } from '@mic-rexjs/usecases/es/types';
|
|
3
3
|
import { ArgumentTypes } from '../../enums/ArgumentTypes';
|
|
4
|
-
import {
|
|
5
|
-
export declare const useContext: <T extends ReducerMap, TUseCaseOptions extends object>(usecase: UseCase<T, TUseCaseOptions>, argumentTypes?: ArgumentTypes) =>
|
|
4
|
+
import { UseCaseContext, UseCaseContextValue } from '../../usecases/contextUseCase/types';
|
|
5
|
+
export declare const useContext: <T extends ReducerMap, TUseCaseOptions extends object>(usecase: UseCase<T, TUseCaseOptions>, argumentTypes?: ArgumentTypes) => UseCaseContext<UseCaseContextValue<T>>;
|
|
@@ -11,7 +11,6 @@ export const useContextualItem = function (contextItem, statuses, createFactory)
|
|
|
11
11
|
cacheCall = _useConstantReducers.cacheCall;
|
|
12
12
|
const onCache = useMemoizedFn(() => {
|
|
13
13
|
const currentFactory = factoryRef.current;
|
|
14
|
-
void depsKey;
|
|
15
14
|
// 防止在以下 `onCreate()` 多次调用实际 `factory`
|
|
16
15
|
return cacheCall(currentFactory, {
|
|
17
16
|
onCompare() {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import { EntityGetter, UseCaseHookOptions } from '../useUseCase/types';
|
|
2
1
|
import { EntityStore } from '@mic-rexjs/usecases';
|
|
3
2
|
import { Statuses } from '../../enums/Statuses';
|
|
4
|
-
import { Dependencies } from '../../types';
|
|
5
|
-
export declare const useEntity: <T,
|
|
3
|
+
import { Dependencies, EntityInitializer } from '../../types';
|
|
4
|
+
export declare const useEntity: <T, TDependencies extends Dependencies = Dependencies>(store: EntityStore<T>, entityArg: T | EntityInitializer<T, TDependencies>, statuses: Statuses) => T;
|
|
@@ -1,77 +1,24 @@
|
|
|
1
|
-
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
1
|
import { useConstantEntityReducers } from '../useConstantEntityReducers';
|
|
3
|
-
import { useContextualItem } from '../useContextualItem';
|
|
4
|
-
import { useRuntimeEntity } from '../useRuntimeEntity';
|
|
5
|
-
import { EntityStore } from '@mic-rexjs/usecases';
|
|
6
|
-
import { useCreation, useLatest, useMemoizedFn, useUpdate } from 'ahooks';
|
|
7
|
-
import { useEffect, useRef } from 'react';
|
|
8
2
|
import { Statuses } from '../../enums/Statuses';
|
|
9
|
-
import { triggerWatchers } from '../../methods/triggerWatchers';
|
|
10
3
|
import { valueUseCase } from '../../usecases/valueUseCase';
|
|
11
|
-
export const useEntity = (
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const current = storeRef.current;
|
|
25
|
-
const _ref = current || {},
|
|
26
|
-
value = _ref.value;
|
|
27
|
-
const _recordValueDiff = recordValueDiff(deps),
|
|
28
|
-
_recordValueDiff2 = _slicedToArray(_recordValueDiff, 2),
|
|
29
|
-
depsDiff = _recordValueDiff2[1];
|
|
30
|
-
const initailEntity = isFunction ? entityArg(value, depsDiff) : entityArg;
|
|
31
|
-
newStore = new EntityStore(initailEntity);
|
|
32
|
-
} else {
|
|
33
|
-
newStore = new EntityStore(null);
|
|
34
|
-
}
|
|
35
|
-
storeRef.current = newStore;
|
|
36
|
-
return newStore;
|
|
37
|
-
}, deps);
|
|
38
|
-
const runtimeEntity = useRuntimeEntity(store, entityArg, contextEntity, statuses);
|
|
39
|
-
const onEntityChange = useMemoizedFn((newEntity, oldEntity) => {
|
|
40
|
-
const _optionsRef$current = optionsRef.current,
|
|
41
|
-
onChange = _optionsRef$current.onChange,
|
|
42
|
-
watch = _optionsRef$current.watch;
|
|
43
|
-
if (watch) {
|
|
44
|
-
triggerWatchers(watch, newEntity, oldEntity);
|
|
45
|
-
}
|
|
46
|
-
onChange === null || onChange === void 0 || onChange(newEntity, oldEntity);
|
|
47
|
-
if (!entityRootEnabled) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
update();
|
|
51
|
-
});
|
|
52
|
-
if (entityRootEnabled) {
|
|
53
|
-
// 执行同步操作
|
|
54
|
-
store.setValue(runtimeEntity, true);
|
|
4
|
+
export const useEntity = (store, entityArg, statuses) => {
|
|
5
|
+
const _useConstantEntityRed = useConstantEntityReducers(entityArg, valueUseCase),
|
|
6
|
+
isValueChanged = _useConstantEntityRed.isValueChanged,
|
|
7
|
+
recordValue = _useConstantEntityRed.recordValue;
|
|
8
|
+
const changed = isValueChanged(entityArg);
|
|
9
|
+
const entityRootDisabled = (statuses & Statuses.EntityRootEnabled) !== Statuses.EntityRootEnabled;
|
|
10
|
+
const isFunction = typeof entityArg === 'function';
|
|
11
|
+
const value = store.value;
|
|
12
|
+
switch (true) {
|
|
13
|
+
case entityRootDisabled:
|
|
14
|
+
case isFunction:
|
|
15
|
+
case !changed:
|
|
16
|
+
return value;
|
|
55
17
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
store.watch(onEntityChange);
|
|
65
|
-
}, [entityEnabled, store, onEntityChange]);
|
|
66
|
-
/**
|
|
67
|
-
* 在变化时候,组件更新前,使用 `unwatch`
|
|
68
|
-
*/
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
return () => {
|
|
71
|
-
store.unwatch(onEntityChange);
|
|
72
|
-
};
|
|
73
|
-
}, [entityEnabled, store, onEntityChange]);
|
|
74
|
-
return useCreation(() => {
|
|
75
|
-
return [runtimeEntity, store];
|
|
76
|
-
}, [runtimeEntity, store]);
|
|
18
|
+
recordValue(entityArg);
|
|
19
|
+
store.disableWatchers();
|
|
20
|
+
// 执行同步操作
|
|
21
|
+
store.setValue(entityArg);
|
|
22
|
+
store.enableWatchers();
|
|
23
|
+
return entityArg;
|
|
77
24
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EntityReducers, EntityUseCase, UseCase } from '@mic-rexjs/usecases';
|
|
2
2
|
import { ReducerMap } from '@mic-rexjs/usecases/es/types';
|
|
3
|
-
import {
|
|
4
|
-
import { Dependencies } from '../../types';
|
|
3
|
+
import { UseCaseHookContextualOptions, UseCaseHookOptions } from '../../hooks/useUseCase/types';
|
|
4
|
+
import { Dependencies, EntityInitializer } from '../../types';
|
|
5
5
|
export type FullParameters<T, TReducers extends ReducerMap, TUseCaseOptions extends object, TDependencies extends Dependencies = Dependencies> = [
|
|
6
|
-
entity: T |
|
|
6
|
+
entity: T | EntityInitializer<T, TDependencies>,
|
|
7
7
|
usecase: UseCase<TReducers, TUseCaseOptions> | EntityUseCase<T, TReducers & EntityReducers<T>, TUseCaseOptions>,
|
|
8
8
|
options: TUseCaseOptions | UseCaseHookOptions<T, TUseCaseOptions> | UseCaseHookContextualOptions<T>,
|
|
9
9
|
deps: TDependencies
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useIsRenderingRef: () => React.
|
|
1
|
+
export declare const useIsRenderingRef: () => React.RefObject<boolean>;
|
|
@@ -2,5 +2,5 @@ import { UseCaseProvider } from './types';
|
|
|
2
2
|
import { EntityStore } from '@mic-rexjs/usecases';
|
|
3
3
|
import { ReducerMap } from '@mic-rexjs/usecases/es/types';
|
|
4
4
|
import { Statuses } from '../../enums/Statuses';
|
|
5
|
-
import {
|
|
6
|
-
export declare const useProvider: <T, TReducers extends ReducerMap>(statuses: Statuses, context:
|
|
5
|
+
import { UseCaseContext, UseCaseContextValue } from '../../usecases/contextUseCase/types';
|
|
6
|
+
export declare const useProvider: <T, TReducers extends ReducerMap>(statuses: Statuses, context: UseCaseContext<UseCaseContextValue<TReducers>>, store: EntityStore<T>, reducers: TReducers) => UseCaseProvider;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { EntityStore } from '@mic-rexjs/usecases';
|
|
2
|
+
import { EntityReducers, EntityUseCase, ReducerMap, UseCase } from '@mic-rexjs/usecases/es/types';
|
|
3
|
+
import { Statuses } from '../../enums/Statuses';
|
|
4
|
+
import { Dependencies } from '../../types';
|
|
5
|
+
import { UseCaseContext, UseCaseContextValue } from '../../usecases/contextUseCase/types';
|
|
6
|
+
export declare const useReducers: <T, TReducers extends ReducerMap, TUseCaseOptions extends object>(usecase: UseCase<TReducers, TUseCaseOptions> | EntityUseCase<T, TReducers & EntityReducers<T>, TUseCaseOptions>, context: UseCaseContext<UseCaseContextValue<TReducers>>, store: EntityStore<T>, statuses: Statuses, options: TUseCaseOptions, deps?: Dependencies) => TReducers;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
|
+
const _excluded = ["watch", "onChange", "options"];
|
|
3
|
+
import { useConstantReducers } from '../useConstantReducers';
|
|
4
|
+
import { useContextualItem } from '../useContextualItem';
|
|
5
|
+
import { createEntityReducers } from '@mic-rexjs/usecases';
|
|
6
|
+
import { useLatest } from 'ahooks';
|
|
7
|
+
import { useContext } from 'react';
|
|
8
|
+
import { Statuses } from '../../enums/Statuses';
|
|
9
|
+
import { methodUseCase } from '../../usecases/methodUseCase';
|
|
10
|
+
export const useReducers = function (usecase, context, store, statuses, options) {
|
|
11
|
+
let deps = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : [];
|
|
12
|
+
const optionsRef = useLatest(options);
|
|
13
|
+
const contextValue = useContext(context);
|
|
14
|
+
const _ref = contextValue || {},
|
|
15
|
+
_ref$reducers = _ref.reducers,
|
|
16
|
+
contextReducers = _ref$reducers === void 0 ? null : _ref$reducers;
|
|
17
|
+
const _useConstantReducers = useConstantReducers(methodUseCase),
|
|
18
|
+
captureCalls = _useConstantReducers.captureCalls;
|
|
19
|
+
return useContextualItem(contextReducers, statuses, () => {
|
|
20
|
+
const opts = captureCalls(options, (key, callArgs) => {
|
|
21
|
+
var _optionsRef$current$k, _optionsRef$current;
|
|
22
|
+
return (_optionsRef$current$k = (_optionsRef$current = optionsRef.current)[key]) === null || _optionsRef$current$k === void 0 ? void 0 : _optionsRef$current$k.call(_optionsRef$current, ...callArgs);
|
|
23
|
+
});
|
|
24
|
+
if ((statuses & Statuses.EntityEnabled) !== Statuses.EntityEnabled) {
|
|
25
|
+
return usecase(opts);
|
|
26
|
+
}
|
|
27
|
+
const hookOptions = opts;
|
|
28
|
+
const watch = hookOptions.watch,
|
|
29
|
+
onChange = hookOptions.onChange,
|
|
30
|
+
usecaseOptions = hookOptions.options,
|
|
31
|
+
restUseCaseOptions = _objectWithoutProperties(hookOptions, _excluded);
|
|
32
|
+
return createEntityReducers(store, usecase, {
|
|
33
|
+
...restUseCaseOptions,
|
|
34
|
+
...usecaseOptions,
|
|
35
|
+
onGenerate(newEntity, result) {
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}, deps);
|
|
40
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ReducerMap } from '@mic-rexjs/usecases/es/types';
|
|
2
2
|
import { ArgumentTypes } from '../../enums/ArgumentTypes';
|
|
3
3
|
import { Statuses } from '../../enums/Statuses';
|
|
4
|
-
import {
|
|
5
|
-
export declare const useStatuses: <T extends ReducerMap>(
|
|
4
|
+
import { UseCaseContext, UseCaseContextValue } from '../../usecases/contextUseCase/types';
|
|
5
|
+
export declare const useStatuses: <T extends ReducerMap>(context: UseCaseContext<UseCaseContextValue<T>>, argumentTypes: ArgumentTypes) => Statuses;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { useCreation } from 'ahooks';
|
|
2
|
+
import { useContext } from 'react';
|
|
2
3
|
import { ArgumentTypes } from '../../enums/ArgumentTypes';
|
|
3
4
|
import { Statuses } from '../../enums/Statuses';
|
|
4
|
-
export const useStatuses = (
|
|
5
|
+
export const useStatuses = (context, argumentTypes) => {
|
|
6
|
+
const contextValue = useContext(context);
|
|
5
7
|
return useCreation(() => {
|
|
6
8
|
let statuses = Statuses.None;
|
|
7
9
|
const _ref = contextValue || {},
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UseCaseHookOptions } from '../useUseCase/types';
|
|
2
|
+
import { EntityReducers, EntityStore } from '@mic-rexjs/usecases';
|
|
3
|
+
import { Statuses } from '../../enums/Statuses';
|
|
4
|
+
import { Dependencies, EntityInitializer } from '../../types';
|
|
5
|
+
import { EntityUseCaseContextValue, UseCaseContext } from '../../usecases/contextUseCase/types';
|
|
6
|
+
export declare const useStore: <T, TUseCaseOptions extends object, TOptions extends UseCaseHookOptions<T, TUseCaseOptions> = UseCaseHookOptions<T, TUseCaseOptions>>(context: UseCaseContext<EntityUseCaseContextValue<T, EntityReducers<T>>>, entity: T | EntityInitializer<T>, statuses: Statuses, options: TOptions, deps?: Dependencies) => EntityStore<T>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import { useConstantEntityReducers } from '../useConstantEntityReducers';
|
|
3
|
+
import { useContextualItem } from '../useContextualItem';
|
|
4
|
+
import { EntityStore } from '@mic-rexjs/usecases';
|
|
5
|
+
import { useCreation, useLatest, useMemoizedFn, useUpdate } from 'ahooks';
|
|
6
|
+
import { useContext, useEffect, useRef } from 'react';
|
|
7
|
+
import { Statuses } from '../../enums/Statuses';
|
|
8
|
+
import { initStore } from '../../methods/initStore';
|
|
9
|
+
import { triggerWatchers } from '../../methods/triggerWatchers';
|
|
10
|
+
import { valueUseCase } from '../../usecases/valueUseCase';
|
|
11
|
+
export const useStore = function (context, entity, statuses, options) {
|
|
12
|
+
let deps = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : [];
|
|
13
|
+
const update = useUpdate();
|
|
14
|
+
const optionsRef = useLatest(options);
|
|
15
|
+
const storeRef = useRef(null);
|
|
16
|
+
const entityEnabled = (statuses & Statuses.EntityEnabled) === Statuses.EntityEnabled;
|
|
17
|
+
const entityRootEnabled = (statuses & Statuses.EntityRootEnabled) === Statuses.EntityRootEnabled;
|
|
18
|
+
const contextValue = useContext(context);
|
|
19
|
+
const _ref = contextValue || {},
|
|
20
|
+
_ref$store = _ref.store,
|
|
21
|
+
contextStore = _ref$store === void 0 ? null : _ref$store;
|
|
22
|
+
const _useConstantEntityRed = useConstantEntityReducers(deps, valueUseCase),
|
|
23
|
+
recordValueDiff = _useConstantEntityRed.recordValueDiff;
|
|
24
|
+
const store = useContextualItem(contextStore, statuses, () => {
|
|
25
|
+
if (!entityRootEnabled) {
|
|
26
|
+
return new EntityStore(null);
|
|
27
|
+
}
|
|
28
|
+
const current = storeRef.current;
|
|
29
|
+
const _recordValueDiff = recordValueDiff(deps),
|
|
30
|
+
_recordValueDiff2 = _slicedToArray(_recordValueDiff, 2),
|
|
31
|
+
changedDeps = _recordValueDiff2[1];
|
|
32
|
+
const newStore = initStore(entity, current, changedDeps);
|
|
33
|
+
storeRef.current = newStore;
|
|
34
|
+
return newStore;
|
|
35
|
+
}, deps);
|
|
36
|
+
const onEntityChange = useMemoizedFn((newEntity, oldEntity) => {
|
|
37
|
+
const _optionsRef$current = optionsRef.current,
|
|
38
|
+
onChange = _optionsRef$current.onChange,
|
|
39
|
+
watch = _optionsRef$current.watch;
|
|
40
|
+
if (watch) {
|
|
41
|
+
triggerWatchers(watch, newEntity, oldEntity);
|
|
42
|
+
}
|
|
43
|
+
onChange === null || onChange === void 0 || onChange(newEntity, oldEntity);
|
|
44
|
+
if (!entityRootEnabled) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
update();
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* 需要马上 `watch`,因为 `useEffect` 在子组件内优先执行,
|
|
51
|
+
* 如果使用了 `setEntity` 则无法监控到变化
|
|
52
|
+
*/
|
|
53
|
+
useCreation(() => {
|
|
54
|
+
if (!entityEnabled) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
store.watch(onEntityChange);
|
|
58
|
+
}, [entityEnabled, store, onEntityChange]);
|
|
59
|
+
/**
|
|
60
|
+
* 在变化时候,组件更新前,使用 `unwatch`
|
|
61
|
+
*/
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
return () => {
|
|
64
|
+
store.unwatch(onEntityChange);
|
|
65
|
+
};
|
|
66
|
+
}, [entityEnabled, store, onEntityChange]);
|
|
67
|
+
return store;
|
|
68
|
+
};
|
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
2
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
-
const _excluded = ["watch", "onChange", "options"];
|
|
4
2
|
import { useArgumentTypes } from '../useArgumentTypes';
|
|
5
3
|
import { useConstantFn } from '../useConstantFn';
|
|
6
4
|
import { useConstantReducers } from '../useConstantReducers';
|
|
7
5
|
import { useContext } from '../useContext';
|
|
8
|
-
import { useContextualItem } from '../useContextualItem';
|
|
9
6
|
import { useEntity } from '../useEntity';
|
|
10
7
|
import { useFullArguments } from '../useFullArguments';
|
|
11
8
|
import { useIsRenderingRef } from '../useIsRenderingRef';
|
|
12
9
|
import { useProvider } from '../useProvider';
|
|
10
|
+
import { useReducers } from '../useReducers';
|
|
13
11
|
import { useStatuses } from '../useStatuses';
|
|
14
|
-
import {
|
|
15
|
-
import { useCreation
|
|
16
|
-
import { useContext as useContextValue } from 'react';
|
|
12
|
+
import { useStore } from '../useStore';
|
|
13
|
+
import { useCreation } from 'ahooks';
|
|
17
14
|
import { Statuses } from '../../enums/Statuses';
|
|
18
15
|
import { methodUseCase } from '../../usecases/methodUseCase';
|
|
19
16
|
export const useUseCase = function () {
|
|
@@ -28,48 +25,15 @@ export const useUseCase = function () {
|
|
|
28
25
|
unsafeUsecase = _fullArguments[1],
|
|
29
26
|
options = _fullArguments[2],
|
|
30
27
|
deps = _fullArguments[3];
|
|
31
|
-
const unkownUsecase = useConstantFn(unsafeUsecase);
|
|
32
|
-
const usecase = unkownUsecase;
|
|
33
|
-
const entityUseCase = unkownUsecase;
|
|
34
|
-
const context = useContext(unkownUsecase, argumentTypes);
|
|
35
|
-
const contextValue = useContextValue(context);
|
|
36
|
-
const entityContextValue = contextValue;
|
|
37
|
-
const statuses = useStatuses(argumentTypes, contextValue);
|
|
38
|
-
const optionsRef = useLatest(options);
|
|
39
|
-
const _ref = contextValue || {},
|
|
40
|
-
_ref$reducers = _ref.reducers,
|
|
41
|
-
contextReducers = _ref$reducers === void 0 ? null : _ref$reducers;
|
|
42
|
-
const _ref2 = entityContextValue || {},
|
|
43
|
-
_ref2$store = _ref2.store,
|
|
44
|
-
contextStore = _ref2$store === void 0 ? null : _ref2$store;
|
|
45
|
-
const _useEntity = useEntity(statuses, unsafeEntity, contextStore, options, deps),
|
|
46
|
-
_useEntity2 = _slicedToArray(_useEntity, 2),
|
|
47
|
-
entity = _useEntity2[0],
|
|
48
|
-
store = _useEntity2[1];
|
|
49
28
|
const _useConstantReducers = useConstantReducers(methodUseCase),
|
|
50
|
-
cacheCalls = _useConstantReducers.cacheCalls
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return usecase(opts);
|
|
59
|
-
}
|
|
60
|
-
const hookOptions = opts;
|
|
61
|
-
const watch = hookOptions.watch,
|
|
62
|
-
onChange = hookOptions.onChange,
|
|
63
|
-
usecaseOptions = hookOptions.options,
|
|
64
|
-
restUseCaseOptions = _objectWithoutProperties(hookOptions, _excluded);
|
|
65
|
-
return createEntityReducers(store, entityUseCase, {
|
|
66
|
-
...restUseCaseOptions,
|
|
67
|
-
...usecaseOptions,
|
|
68
|
-
onGenerate(newEntity, result) {
|
|
69
|
-
return result;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
}, deps);
|
|
29
|
+
cacheCalls = _useConstantReducers.cacheCalls;
|
|
30
|
+
const usecase = useConstantFn(unsafeUsecase);
|
|
31
|
+
const context = useContext(usecase, argumentTypes);
|
|
32
|
+
const entityContext = context;
|
|
33
|
+
const statuses = useStatuses(context, argumentTypes);
|
|
34
|
+
const store = useStore(entityContext, unsafeEntity, statuses, options, deps);
|
|
35
|
+
const entity = useEntity(store, unsafeEntity, statuses);
|
|
36
|
+
const reducers = useReducers(usecase, context, store, statuses, options, deps);
|
|
73
37
|
const Provider = useProvider(statuses, context, store, reducers);
|
|
74
38
|
return useCreation(() => {
|
|
75
39
|
if ((statuses & Statuses.EntityEnabled) !== Statuses.EntityEnabled) {
|