@mic-rexjs/usecases-react 2.10.3 → 2.11.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/es/hooks/useConstantEntityReducers/index.d.ts +3 -0
- package/es/hooks/useConstantEntityReducers/index.js +7 -0
- package/es/hooks/useConstantReducers/index.d.ts +3 -0
- package/es/hooks/useConstantReducers/index.js +6 -0
- package/es/hooks/useContextualItem/index.d.ts +2 -1
- package/es/hooks/useContextualItem/index.js +5 -3
- package/es/hooks/useDepsKey/index.d.ts +1 -1
- package/es/hooks/useDepsKey/index.js +2 -2
- package/es/hooks/useEntity/index.d.ts +2 -1
- package/es/hooks/useEntity/index.js +11 -3
- package/es/hooks/useFullArguments/types.d.ts +3 -3
- package/es/hooks/useRuntimeEntity/index.d.ts +2 -1
- package/es/hooks/useRuntimeEntity/index.js +4 -3
- package/es/hooks/useUseCase/index.js +13 -8
- package/es/hooks/useUseCase/index.test.js +60 -0
- package/es/hooks/useUseCase/types.d.ts +3 -3
- package/es/usecases/valueUseCase/index.js +50 -16
- package/es/usecases/valueUseCase/types.d.ts +7 -2
- package/lib/hooks/useConstantEntityReducers/index.js +13 -0
- package/lib/hooks/useConstantReducers/index.js +12 -0
- package/lib/hooks/useContextualItem/index.js +6 -4
- package/lib/hooks/useDepsKey/index.js +3 -3
- package/lib/hooks/useEntity/index.js +15 -4
- package/lib/hooks/useRuntimeEntity/index.js +6 -5
- package/lib/hooks/useUseCase/index.js +19 -11
- package/lib/hooks/useUseCase/index.test.js +152 -72
- package/lib/usecases/valueUseCase/index.js +86 -42
- package/package.json +2 -2
- package/es/hooks/useEntityReducers/index.d.ts +0 -4
- package/es/hooks/useEntityReducers/index.js +0 -18
- package/es/hooks/useReducers/index.d.ts +0 -4
- package/es/hooks/useReducers/index.js +0 -13
- package/es/methods/initEntityReducers/index.d.ts +0 -5
- package/es/methods/initEntityReducers/index.js +0 -11
- package/lib/hooks/useEntityReducers/index.js +0 -30
- package/lib/hooks/useReducers/index.js +0 -20
- package/lib/methods/initEntityReducers/index.js +0 -24
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 l?o:l,c=Object.create(i.prototype);return n(c,"_invoke",function(t,n,o){var u,a,i,c=0,l=o||[],f=!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;!f&&c&&!o&&r<l.length;r++){var o,u=l[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 f=!0,n}return function(o,l,v){if(c>1)throw TypeError("Generator is already running");for(f&&1===l&&y(l,v),a=l,i=v;(r=a<2?e:i)||!f;){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=(f=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:f}}}(t,u,a),!0),c}var s={};function l(){}function f(){}function p(){}r=Object.getPrototypeOf;var y=[][a]?r(r([][a]())):(n(r={},a,function(){return this}),r),v=p.prototype=l.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 f.prototype=p,n(v,"constructor",p),n(p,"constructor",f),f.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 l(){"use strict";var e=o(),r=e.m(l),f=(Object.getPrototypeOf?Object.getPrototypeOf(r):r.__proto__).constructor;function p(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===f||"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=l=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=l,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:()=>F,useUseCase:()=>A});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 l=usecases;var f=["watch","onChange","options"];function p(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 y(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?p(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):p(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}const v=React;var d,b=r.n(v),h=function(t){return s((0,v.useState)(t),1)[0]};!function(t){t[t.None=0]="None",t[t.Entity=2]="Entity"}(d||(d={}));var m=function(t){return s((0,v.useState)(function(){return t}),1)[0]};const O=ahooks;var g;!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"}(g||(g={}));var x=(0,l.createUseCase)(function(){var t=new Map,e=(0,v.createContext)(null);return function(){return{createContextValue:function(t,e,r){return(r&g.EntityEnabled)===g.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&d.Entity)!==d.Entity)return e;var i=(0,v.createContext)(null);return t.set(r,{value:i,times:1}),i},unregisterUseCase:function(e,r){if((r&d.Entity)!==d.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}}}}),E=r(756),j=r.n(E);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 P(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 S=(0,l.createUseCase)(function(){var e=0;return function(){var r=e++,n=(0,l.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){if(e===r)return!0;var n="object"===t(e)&&null!==e,o="object"===t(r)&&null!==r;if(!n||!o)return!1;var u=Object.keys(e),a=Object.keys(r);if(u.length!==a.length)return!1;for(var i=0,c=u;i<c.length;i++){var s=c[i];if(e[s]!==r[s])return!1}return!0},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)}),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)});return P(P({},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 l=i.shift(),f=l.oldValue,p=l.newValue,y=l.fieldPaths,v=s(a.match(/^([^.]+)\.(.+)$/)||[],3),d=v[1],b=void 0===d?a:d,h=v[2],m=void 0===h?"":h,O=o(f,b),g=o(p,b);if(O||g){var x=O?f[b]:void 0,E=g?p[b]:void 0,j={fieldPaths:[].concat(c(y),[b]),newEntity:e,newValue:E,oldEntity:t,oldValue:x};if(m){a=m,i.push(j);continue}if(x===E)continue;u=!1,null==n||n(j)}else if(!/^\d+^/.test(b))for(var w=Array.isArray(f)?f:[],P=Array.isArray(p)?p:[],S=w.length,C=P.length,_=Math.max(S,C),M=0;M<_;M++)i.push({fieldPaths:[].concat(c(y),["".concat(M)]),newEntity:e,newValue:P[M],oldEntity:t,oldValue:w[M]})}while(i.length>0);return u},recordValue:i,recordValueMatch:f,recordValueMatchWith:function(t,n){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e+1;return j().mark(function u(){return j().wrap(function(u){for(;;)switch(u.prev=u.next){case 0:return u.delegateYield(f(t,n),"t0",1);case 1:return u.t0||(e++,r=o),u.abrupt("return",r);case 2:case"end":return u.stop()}},u)})()}})}}),C=function(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:[],o=s((0,h(function(){return(0,l.createEntityReducers)(n,S)}).recordValueMatchWith)(n),2)[1],u=(0,O.useMemoizedFn)(function(){return(0,l.createEntityReducers)(t,e,r)});return(0,O.useCreation)(function(){return u()},[o,e,u])},_=function(t){return s((0,C(t,S).recordValueMatchWith)(t),2)[1]},M=function(t,e){var r=_(arguments.length>2&&void 0!==arguments[2]?arguments[2]:[]),n=(0,O.useMemoizedFn)(function(){return t(e)});return(0,O.useCreation)(function(){return n()},[r,t,n])},k=function(){var t=S().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,l=i.returnValue;if(c(s,o))return l}var f=e.apply(void 0,o);return t&&(n={parameters:o,returnValue:f}),f}};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}}},R=function(t,e,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,o=(0,O.useLatest)(r),u=M(k).cacheCall,a=(0,O.useMemoizedFn)(function(){var t=o.current;return u(t,{onCompare:function(){return!0}})}),i=(0,O.useCreation)(function(){return a()},[n,a]);return(0,O.useCreation)(function(){return(e&g.RootEnabled)!==g.RootEnabled&&t?t:i()},[e,t,i])};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}var A=function(){for(var r,n=(r=(0,O.useLatest)(!0),(0,v.useEffect)(function(){r.current=!1}),r),u=arguments.length,a=new Array(u),i=0;i<u;i++)a[i]=arguments[i];var p=function(e){return h(function(){return"function"===t(s(e,2)[1])?d.Entity:d.None})}(a),E=function(t,e){var r=s(t,4),n=r[0],o=r[1],u=r[2],a=r[3];return(e&d.Entity)!==d.Entity?[null,n,o||{},u||[]]:[n,o,u||{},a||[]]}(a,p),j=s(E,4),w=j[0],P=j[1],A=j[2],D=j[3],N=m(P),T=N,U=N,F=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:d.None,r=h(function(){return(0,x().registerUseCase)(t,e)});return(0,O.useUnmount)(function(){(0,x().unregisterUseCase)(t,e)}),r}(N,p),G=(0,v.useContext)(F),I=G,L=function(t,e){return(0,O.useCreation)(function(){var r=g.None,n=(e||{}).store;return(t&d.Entity)===d.Entity&&(r|=g.EntityRootEnabled),r|=e?g.ContextEnabled:g.RootEnabled,n&&(r|=g.EntityEnabled),r},[t,e])}(p,G),z=(0,O.useLatest)(A),$=_(D),W=(G||{}).reducers,Y=void 0===W?null:W,q=(I||{}).store,B=s(function(t,e,r,n,o){var u=(0,O.useUpdate)(),a=(0,v.useRef)(null),i=(0,O.useLatest)(n),c=r?r.value:null,f=(t&g.EntityEnabled)===g.EntityEnabled,p=(t&g.EntityRootEnabled)===g.EntityRootEnabled,y=R(r,t,function(){var t;if(p){var r,n="function"==typeof e?e(null===(r=a.current)||void 0===r?void 0:r.value):e;t=new l.EntityStore(n)}else t=new l.EntityStore(null);return a.current=t,t},o),d=function(t,e,r,n){var o=C(e,S),u=o.isValueChanged,a=o.recordValue,i=u(e);if((n&g.EntityRootEnabled)!==g.EntityRootEnabled)return r;switch(!0){case"function"==typeof e:case!i:return t.value}return a(e),e}(y,e,c,t),b=(0,O.useMemoizedFn)(function(t,e){var r=i.current,n=r.onChange,o=r.watch;o&&function(t,e,r){for(var n=S().matchProperty,o=function(){var t=s(a[u],2),o=t[0],i=t[1];n(r,e,o,function(t){i(t)})},u=0,a=Object.entries(t);u<a.length;u++)o()}(o,t,e),null==n||n(t,e),p&&u()});return p&&y.setValue(d,!0),(0,O.useCreation)(function(){f&&y.watch(b)},[f,y,b]),(0,v.useEffect)(function(){return function(){y.unwatch(b)}},[f,y,b]),(0,O.useCreation)(function(){return[d,y]},[d,y])}(L,w,void 0===q?null:q,A,$),2),H=B[0],J=B[1],K=M(k),Q=K.cacheCalls,X=K.captureCalls,Z=R(Y,L,function(){var t=X(A,function(t,e){var r,n;return null===(r=(n=z.current)[t])||void 0===r?void 0:r.call.apply(r,[n].concat(c(e)))});return(L&g.EntityEnabled)!==g.EntityEnabled?T(t):function(t,e,r){r.watch,r.onChange;var n=r.options,u=o(r,f);return(0,l.createEntityReducers)(e,t,y(y(y({},u),n),{},{onGenerate:function(t,e){return e}}))}(U,J,t)},$),tt=function(t,e,r,n){var o=r.value,u=(0,O.useCreation)(function(){return(0,x().createContextValue)(r,n,t)},[t,o,r,n]),a=(0,O.useLatest)(u);return m(function(t){var r=t.children,n=t.with,o=void 0===n?[]:n,u=e.Provider,i=a.current;return b().createElement(u,{value:i},o.reduceRight(function(t,e){return b().createElement(e,{},t)},r))})}(L,F,J,Z);return(0,O.useCreation)(function(){if((L&g.EntityEnabled)!==g.EntityEnabled)return Z;var r=(L&g.RootEnabled)===g.RootEnabled,o=Q(Z,{onShouldCache:function(){return n.current}}),u=null===H,a=Array.isArray(H),i="object"!==t(H)||u||a?H:function(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}({},H);return r?[i,o,tt]:[i,o]},[L,H,Z,tt,n,Q])},D=function(t){var e=t.usecase,r=t.watch,n=t.onMount,o=t.onChange,a=s(A(e,{watch:r,onChange:o}),1)[0];return(0,O.useMount)(function(){null==n||n(a)}),(0,u.jsx)(v.Fragment,{})},N=["usecase"];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 U(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 F=function(t){var e=t.usecase,r=o(t,N),n=(0,A(x).getUseCaseContext)(e),a=(0,v.useContext)(n);return(0,u.jsx)(v.Fragment,{children:null===a?null:(0,u.jsx)(D,U({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 l?o:l,c=Object.create(i.prototype);return n(c,"_invoke",function(t,n,o){var u,a,i,c=0,l=o||[],f=!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;!f&&c&&!o&&r<l.length;r++){var o,u=l[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 f=!0,n}return function(o,l,v){if(c>1)throw TypeError("Generator is already running");for(f&&1===l&&y(l,v),a=l,i=v;(r=a<2?e:i)||!f;){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=(f=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:f}}}(t,u,a),!0),c}var s={};function l(){}function f(){}function p(){}r=Object.getPrototypeOf;var y=[][a]?r(r([][a]())):(n(r={},a,function(){return this}),r),v=p.prototype=l.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 f.prototype=p,n(v,"constructor",p),n(p,"constructor",f),f.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 l(){"use strict";var e=o(),r=e.m(l),f=(Object.getPrototypeOf?Object.getPrototypeOf(r):r.__proto__).constructor;function p(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===f||"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=l=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=l,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:()=>R});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 l=React;var f,p=r.n(l),y=function(t){return s((0,l.useState)(t),1)[0]};!function(t){t[t.None=0]="None",t[t.Entity=2]="Entity"}(f||(f={}));var v=function(t){return s((0,l.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,l.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&f.Entity)!==f.Entity)return e;var i=(0,l.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}}}}),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,l=[].concat(i,c),f="function"==typeof n,p=0,y=l.length;p<y;p++){var v=l[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,!f)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)}),l=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)}),f=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(f(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 l=i.shift(),f=l.oldValue,p=l.newValue,y=l.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(f,b),g=o(p,b);if(x||g){var O=x?f[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(f)?f:[],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:l,recordValueMatch:f,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,l=i.returnValue;if(c(s,o))return l}var f=e.apply(void 0,o);return t&&(n={parameters:o,returnValue:f}),f}};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])},_=["watch","onChange","options"];function M(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 k(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?M(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):M(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var R=function(){for(var e,r=(e=(0,b.useLatest)(!0),(0,l.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])?f.Entity:f.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&f.Entity)!==f.Entity?[null,n,o||{},u||[]]:[n,o,u||{},a||[]]}(u,i),E=s(O,4),w=E[0],j=E[1],M=E[2],R=E[3],V=v(j),A=V,N=V,U=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:f.None,r=y(function(){return(0,x().registerUseCase)(t,e)});return(0,b.useUnmount)(function(){(0,x().unregisterUseCase)(t,e)}),r}(V,i),D=(0,l.useContext)(U),T=D,F=function(t,e){return(0,b.useCreation)(function(){var r=m.None,n=(e||{}).store;return(t&f.Entity)===f.Entity&&(r|=m.EntityRootEnabled),r|=e?m.ContextEnabled:m.RootEnabled,n&&(r|=m.EntityEnabled),r},[t,e])}(i,D),G=(0,b.useLatest)(M),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,l.useRef)(null),i=(0,b.useLatest)(n),c=r?r.value:null,f=(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=C().matchProperty,o=function(){var t=s(a[u],2),o=t[0],i=t[1];n(r,e,o,function(t){i(t)})},u=0,a=Object.entries(t);u<a.length;u++)o()}(o,t,e),null==n||n(t,e),p&&u()});return p&&v.setValue(d,!0),(0,b.useCreation)(function(){f&&v.watch(x)},[f,v,x]),(0,l.useEffect)(function(){return function(){v.unwatch(x)}},[f,v,x]),(0,b.useCreation)(function(){return[d,v]},[d,v])}(F,w,void 0===$?null:$,M,R),2),W=z[0],Y=z[1],K=d(S),q=K.cacheCalls,B=K.captureCalls,H=P(L,F,function(){var t=B(M,function(t,e){var r,n;return null===(r=(n=G.current)[t])||void 0===r?void 0:r.call.apply(r,[n].concat(c(e)))});if((F&m.EntityEnabled)!==m.EntityEnabled)return A(t);var e=t,r=(e.watch,e.onChange,e.options),n=o(e,_);return(0,h.createEntityReducers)(Y,N,k(k(k({},n),r),{},{onGenerate:function(t,e){return e}}))},R),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=(F&m.RootEnabled)===m.RootEnabled,n=q(H,{onShouldCache:function(){return r.current}}),o=null===W,u=Array.isArray(W),a="object"!==t(W)||o||u?W:k({},W);return e?[a,n,J]:[a,n]},[F,W,H,J,r,q])},V=function(t){var e=t.usecase,r=t.watch,n=t.onMount,o=t.onChange,a=s(R(e,{watch:r,onChange:o}),1)[0];return(0,b.useMount)(function(){null==n||n(a)}),(0,u.jsx)(l.Fragment,{})},A=["usecase"];function N(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 U(t){for(var r=1;r<arguments.length;r++){var n=null!=arguments[r]?arguments[r]:{};r%2?N(Object(n),!0).forEach(function(r){e(t,r,n[r])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):N(Object(n)).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))})}return t}var D=function(t){var e=t.usecase,r=o(t,A),n=(0,R(x).getUseCaseContext)(e),a=(0,l.useContext)(n);return(0,u.jsx)(l.Fragment,{children:null===a?null:(0,u.jsx)(V,U({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})})();
|
|
@@ -0,0 +1,3 @@
|
|
|
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>>;
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
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,3 +1,4 @@
|
|
|
1
1
|
import { CreateContextualItemFactory } from './types';
|
|
2
2
|
import { Statuses } from '../../enums/Statuses';
|
|
3
|
-
|
|
3
|
+
import { Dependencies } from '../../types';
|
|
4
|
+
export declare const useContextualItem: <T>(contextItem: T | null, statuses: Statuses, createFactory: CreateContextualItemFactory<T>, deps?: Dependencies) => T;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useConstantReducers } from '../useConstantReducers';
|
|
2
|
+
import { useDepsKey } from '../useDepsKey';
|
|
2
3
|
import { useCreation, useLatest, useMemoizedFn } from 'ahooks';
|
|
3
4
|
import { Statuses } from '../../enums/Statuses';
|
|
4
5
|
import { methodUseCase } from '../../usecases/methodUseCase';
|
|
5
|
-
export const useContextualItem = (contextItem, statuses, createFactory,
|
|
6
|
+
export const useContextualItem = (contextItem, statuses, createFactory, deps = []) => {
|
|
7
|
+
const depsKey = useDepsKey(deps);
|
|
6
8
|
const factoryRef = useLatest(createFactory);
|
|
7
|
-
const { cacheCall } =
|
|
9
|
+
const { cacheCall } = useConstantReducers(methodUseCase);
|
|
8
10
|
const onCache = useMemoizedFn(() => {
|
|
9
11
|
const { current: currentFactory } = factoryRef;
|
|
10
12
|
void depsKey;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Dependencies } from '../../types';
|
|
2
|
-
export declare const useDepsKey: (deps: Dependencies) =>
|
|
2
|
+
export declare const useDepsKey: (deps: Dependencies) => React.Key;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useConstantEntityReducers } from '../useConstantEntityReducers';
|
|
2
2
|
import { valueUseCase } from '../../usecases/valueUseCase';
|
|
3
3
|
export const useDepsKey = (deps) => {
|
|
4
|
-
const { recordValueMatchWith } =
|
|
4
|
+
const { recordValueMatchWith } = useConstantEntityReducers(deps, (valueUseCase));
|
|
5
5
|
const [, depsKey] = recordValueMatchWith(deps);
|
|
6
6
|
return depsKey;
|
|
7
7
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EntityGetter, UseCaseHookOptions } from '../useUseCase/types';
|
|
2
2
|
import { EntityStore } from '@mic-rexjs/usecases';
|
|
3
3
|
import { Statuses } from '../../enums/Statuses';
|
|
4
|
-
|
|
4
|
+
import { Dependencies } from '../../types';
|
|
5
|
+
export declare const useEntity: <T, TUseCaseOptions extends object, TOptions extends UseCaseHookOptions<T, TUseCaseOptions> = UseCaseHookOptions<T, TUseCaseOptions>, TDependencies extends Dependencies = Dependencies>(statuses: Statuses, entityArg: T | EntityGetter<T, TDependencies>, contextStore: EntityStore<T> | null, options: TOptions, deps: TDependencies) => [entity: T, store: EntityStore<T>];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useConstantEntityReducers } from '../useConstantEntityReducers';
|
|
1
2
|
import { useContextualItem } from '../useContextualItem';
|
|
2
3
|
import { useRuntimeEntity } from '../useRuntimeEntity';
|
|
3
4
|
import { EntityStore } from '@mic-rexjs/usecases';
|
|
@@ -5,18 +6,25 @@ import { useCreation, useLatest, useMemoizedFn, useUpdate } from 'ahooks';
|
|
|
5
6
|
import { useEffect, useRef } from 'react';
|
|
6
7
|
import { Statuses } from '../../enums/Statuses';
|
|
7
8
|
import { triggerWatchers } from '../../methods/triggerWatchers';
|
|
8
|
-
|
|
9
|
+
import { valueUseCase } from '../../usecases/valueUseCase';
|
|
10
|
+
export const useEntity = (statuses, entityArg, contextStore, options, deps) => {
|
|
9
11
|
const update = useUpdate();
|
|
10
12
|
const storeRef = useRef(null);
|
|
11
13
|
const optionsRef = useLatest(options);
|
|
12
14
|
const contextEntity = (contextStore ? contextStore.value : null);
|
|
13
15
|
const entityEnabled = (statuses & Statuses.EntityEnabled) === Statuses.EntityEnabled;
|
|
14
16
|
const entityRootEnabled = (statuses & Statuses.EntityRootEnabled) === Statuses.EntityRootEnabled;
|
|
17
|
+
const { recordValueDiff } = useConstantEntityReducers(deps, (valueUseCase));
|
|
15
18
|
const store = useContextualItem(contextStore, statuses, () => {
|
|
16
19
|
let newStore;
|
|
17
20
|
if (entityRootEnabled) {
|
|
18
21
|
const isFunction = typeof entityArg === 'function';
|
|
19
|
-
const
|
|
22
|
+
const { current } = storeRef;
|
|
23
|
+
const { value } = current || {};
|
|
24
|
+
const [, depsDiff] = recordValueDiff(deps);
|
|
25
|
+
const initailEntity = isFunction
|
|
26
|
+
? entityArg(value, depsDiff)
|
|
27
|
+
: entityArg;
|
|
20
28
|
newStore = new EntityStore(initailEntity);
|
|
21
29
|
}
|
|
22
30
|
else {
|
|
@@ -24,7 +32,7 @@ export const useEntity = (statuses, entityArg, contextStore, options, depsKey) =
|
|
|
24
32
|
}
|
|
25
33
|
storeRef.current = newStore;
|
|
26
34
|
return newStore;
|
|
27
|
-
},
|
|
35
|
+
}, deps);
|
|
28
36
|
const runtimeEntity = useRuntimeEntity(store, entityArg, contextEntity, statuses);
|
|
29
37
|
const onEntityChange = useMemoizedFn((newEntity, oldEntity) => {
|
|
30
38
|
const { onChange, watch } = optionsRef.current;
|
|
@@ -2,9 +2,9 @@ import { EntityReducers, EntityUseCase, UseCase } from '@mic-rexjs/usecases';
|
|
|
2
2
|
import { ReducerMap } from '@mic-rexjs/usecases/es/types';
|
|
3
3
|
import { EntityGetter, UseCaseHookContextualOptions, UseCaseHookOptions } from '../../hooks/useUseCase/types';
|
|
4
4
|
import { Dependencies } from '../../types';
|
|
5
|
-
export type FullParameters<T, TReducers extends ReducerMap, TUseCaseOptions extends object> = [
|
|
6
|
-
entity: T | EntityGetter<T>,
|
|
5
|
+
export type FullParameters<T, TReducers extends ReducerMap, TUseCaseOptions extends object, TDependencies extends Dependencies = Dependencies> = [
|
|
6
|
+
entity: T | EntityGetter<T, TDependencies>,
|
|
7
7
|
usecase: UseCase<TReducers, TUseCaseOptions> | EntityUseCase<T, TReducers & EntityReducers<T>, TUseCaseOptions>,
|
|
8
8
|
options: TUseCaseOptions | UseCaseHookOptions<T, TUseCaseOptions> | UseCaseHookContextualOptions<T>,
|
|
9
|
-
deps:
|
|
9
|
+
deps: TDependencies
|
|
10
10
|
];
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EntityStore } from '@mic-rexjs/usecases';
|
|
2
2
|
import { Statuses } from '../../enums/Statuses';
|
|
3
3
|
import { EntityGetter } from '../../hooks/useUseCase/types';
|
|
4
|
-
|
|
4
|
+
import { Dependencies } from '../../types';
|
|
5
|
+
export declare const useRuntimeEntity: <T, TDependencies extends Dependencies = Dependencies>(store: EntityStore<T>, entityArg: T | EntityGetter<T, TDependencies>, contextEntity: T, statuses: Statuses) => T;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useConstantEntityReducers } from '../useConstantEntityReducers';
|
|
2
2
|
import { Statuses } from '../../enums/Statuses';
|
|
3
3
|
import { valueUseCase } from '../../usecases/valueUseCase';
|
|
4
4
|
export const useRuntimeEntity = (store, entityArg, contextEntity, statuses) => {
|
|
5
|
-
const { isValueChanged, recordValue } =
|
|
5
|
+
const { isValueChanged, recordValue } = useConstantEntityReducers(entityArg, (valueUseCase));
|
|
6
6
|
const changed = isValueChanged(entityArg);
|
|
7
7
|
const entityRootDisabled = (statuses & Statuses.EntityRootEnabled) !== Statuses.EntityRootEnabled;
|
|
8
8
|
if (entityRootDisabled) {
|
|
9
9
|
return contextEntity;
|
|
10
10
|
}
|
|
11
11
|
const isFunction = typeof entityArg === 'function';
|
|
12
|
+
const { value } = store;
|
|
12
13
|
switch (true) {
|
|
13
14
|
case isFunction:
|
|
14
15
|
case !changed:
|
|
15
|
-
return
|
|
16
|
+
return value;
|
|
16
17
|
}
|
|
17
18
|
recordValue(entityArg);
|
|
18
19
|
return entityArg;
|
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { initEntityReducers } from '../../methods/initEntityReducers';
|
|
2
1
|
import { useArgumentTypes } from '../useArgumentTypes';
|
|
3
2
|
import { useConstantFn } from '../useConstantFn';
|
|
3
|
+
import { useConstantReducers } from '../useConstantReducers';
|
|
4
4
|
import { useContext } from '../useContext';
|
|
5
5
|
import { useContextualItem } from '../useContextualItem';
|
|
6
|
-
import { useDepsKey } from '../useDepsKey';
|
|
7
6
|
import { useEntity } from '../useEntity';
|
|
8
7
|
import { useFullArguments } from '../useFullArguments';
|
|
9
8
|
import { useIsRenderingRef } from '../useIsRenderingRef';
|
|
10
9
|
import { useProvider } from '../useProvider';
|
|
11
|
-
import { useReducers } from '../useReducers';
|
|
12
10
|
import { useStatuses } from '../useStatuses';
|
|
11
|
+
import { createEntityReducers } from '@mic-rexjs/usecases';
|
|
13
12
|
import { useCreation, useLatest } from 'ahooks';
|
|
14
13
|
import { useContext as useContextValue } from 'react';
|
|
15
14
|
import { Statuses } from '../../enums/Statuses';
|
|
@@ -27,11 +26,10 @@ export const useUseCase = ((...args) => {
|
|
|
27
26
|
const entityContextValue = contextValue;
|
|
28
27
|
const statuses = useStatuses(argumentTypes, contextValue);
|
|
29
28
|
const optionsRef = useLatest(options);
|
|
30
|
-
const depsKey = useDepsKey(deps);
|
|
31
29
|
const { reducers: contextReducers = null } = contextValue || {};
|
|
32
30
|
const { store: contextStore = null } = entityContextValue || {};
|
|
33
|
-
const [entity, store] = useEntity(statuses, unsafeEntity, contextStore, options,
|
|
34
|
-
const { cacheCalls, captureCalls } =
|
|
31
|
+
const [entity, store] = useEntity(statuses, unsafeEntity, contextStore, options, deps);
|
|
32
|
+
const { cacheCalls, captureCalls } = useConstantReducers(methodUseCase);
|
|
35
33
|
const reducers = useContextualItem(contextReducers, statuses, () => {
|
|
36
34
|
const opts = captureCalls(options, (key, callArgs) => {
|
|
37
35
|
return optionsRef.current[key]?.(...callArgs);
|
|
@@ -40,8 +38,15 @@ export const useUseCase = ((...args) => {
|
|
|
40
38
|
return usecase(opts);
|
|
41
39
|
}
|
|
42
40
|
const hookOptions = opts;
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
const { watch, onChange, options: usecaseOptions, ...restUseCaseOptions } = hookOptions;
|
|
42
|
+
return createEntityReducers(store, entityUseCase, {
|
|
43
|
+
...restUseCaseOptions,
|
|
44
|
+
...usecaseOptions,
|
|
45
|
+
onGenerate(newEntity, result) {
|
|
46
|
+
return result;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}, deps);
|
|
45
50
|
const Provider = useProvider(statuses, context, store, reducers);
|
|
46
51
|
return useCreation(() => {
|
|
47
52
|
if ((statuses & Statuses.EntityEnabled) !== Statuses.EntityEnabled) {
|
|
@@ -193,6 +193,66 @@ describe('useUseCase', () => {
|
|
|
193
193
|
const { current: [currentFile], } = result;
|
|
194
194
|
expect(currentFile).toEqual(file);
|
|
195
195
|
});
|
|
196
|
+
test('Entity getter should provide the current entity', () => {
|
|
197
|
+
let updateIndex = 0;
|
|
198
|
+
const file = defaultFile;
|
|
199
|
+
const onFile = jest.fn();
|
|
200
|
+
const { result } = renderHook(() => {
|
|
201
|
+
return useUseCase((currentFile) => {
|
|
202
|
+
onFile(currentFile);
|
|
203
|
+
return currentFile ?? file;
|
|
204
|
+
}, fileUseCase, {}, [updateIndex++]);
|
|
205
|
+
});
|
|
206
|
+
const { current: [, { setPath: setPath1 }], } = result;
|
|
207
|
+
expect(onFile).toHaveBeenCalledTimes(1);
|
|
208
|
+
expect(onFile).toHaveBeenCalledWith(void 0);
|
|
209
|
+
act(() => {
|
|
210
|
+
setPath1(PATH_1);
|
|
211
|
+
});
|
|
212
|
+
const { current: [, { setPath: setPath2 }], } = result;
|
|
213
|
+
expect(onFile).toHaveBeenCalledTimes(2);
|
|
214
|
+
expect(onFile).toHaveBeenCalledWith({ ...file, ext: EXT_1, path: PATH_1 });
|
|
215
|
+
act(() => {
|
|
216
|
+
setPath2(PATH_2);
|
|
217
|
+
});
|
|
218
|
+
expect(onFile).toHaveBeenCalledTimes(3);
|
|
219
|
+
expect(onFile).toHaveBeenCalledWith({ ...file, ext: EXT_2, path: PATH_2 });
|
|
220
|
+
});
|
|
221
|
+
test('Entity getter should provide the changed deps', () => {
|
|
222
|
+
let updateIndex = 0;
|
|
223
|
+
const file = defaultFile;
|
|
224
|
+
const symbol = Symbol('changedDep');
|
|
225
|
+
const onChangedDeps = jest.fn();
|
|
226
|
+
const { result } = renderHook(() => {
|
|
227
|
+
return useUseCase((currentFile = file, changedDeps) => {
|
|
228
|
+
// 验证参数类型
|
|
229
|
+
const [index1, num1, index2, string1, index3, boolean1] = changedDeps;
|
|
230
|
+
const a = index1;
|
|
231
|
+
const b = num1;
|
|
232
|
+
const c = index2;
|
|
233
|
+
const d = string1;
|
|
234
|
+
const e = index3;
|
|
235
|
+
const f = boolean1;
|
|
236
|
+
void a;
|
|
237
|
+
void b;
|
|
238
|
+
void c;
|
|
239
|
+
void d;
|
|
240
|
+
void e;
|
|
241
|
+
void f;
|
|
242
|
+
// 先 `fill` 填充,再合并,以 `symbol` 代替虚无项去匹配
|
|
243
|
+
onChangedDeps(Object.assign([...changedDeps].fill(symbol), changedDeps));
|
|
244
|
+
return currentFile;
|
|
245
|
+
}, fileUseCase, {}, [updateIndex++, 0, updateIndex++, 'xyz', updateIndex++, false]);
|
|
246
|
+
});
|
|
247
|
+
const { current: [, { setPath: setPath }], } = result;
|
|
248
|
+
expect(onChangedDeps).toHaveBeenCalledTimes(1);
|
|
249
|
+
expect(onChangedDeps).toHaveBeenCalledWith([symbol, symbol, symbol, symbol, symbol, symbol]);
|
|
250
|
+
act(() => {
|
|
251
|
+
setPath(PATH_1);
|
|
252
|
+
});
|
|
253
|
+
expect(onChangedDeps).toHaveBeenCalledTimes(2);
|
|
254
|
+
expect(onChangedDeps).toHaveBeenCalledWith([3, symbol, 4, symbol, 5, symbol]);
|
|
255
|
+
});
|
|
196
256
|
test('Entity property getter should always return the same object if nothing changed after component update', () => {
|
|
197
257
|
let updateTimes = 0;
|
|
198
258
|
const data = {
|
|
@@ -17,8 +17,8 @@ export type ContextualCoreCollection<T, TEntityReducers extends EntityReducerMap
|
|
|
17
17
|
reducers: ContextualEntityReducers<T, TEntityReducers>
|
|
18
18
|
];
|
|
19
19
|
export type CoreCollection<T, TEntityReducers extends EntityReducerMap<T>> = RootCoreCollection<T, TEntityReducers> | ContextualCoreCollection<T, TEntityReducers>;
|
|
20
|
-
export interface EntityGetter<T> {
|
|
21
|
-
(entity
|
|
20
|
+
export interface EntityGetter<T, TDependencies extends Dependencies = Dependencies> {
|
|
21
|
+
(entity: T | undefined, changedDeps: TDependencies): T;
|
|
22
22
|
}
|
|
23
23
|
export interface EntityWatchEvent<T, TValue = unknown> extends MatchPropertyFailedResult<T, TValue> {
|
|
24
24
|
}
|
|
@@ -54,7 +54,7 @@ export interface ContextualCoreCollectionHook {
|
|
|
54
54
|
<T, TEntityReducers extends EntityReducerMap<T>>(usecase: InferableEntityUseCase<T, TEntityReducers>, options?: UseCaseHookContextualOptions<T>, deps?: Dependencies): ContextualCoreCollection<T, TEntityReducers>;
|
|
55
55
|
}
|
|
56
56
|
export interface RootCoreCollectionHook {
|
|
57
|
-
<T, TEntityReducers extends EntityReducerMap<T>, TUseCaseOptions extends object = object>(entity: T | EntityGetter<T>, usecase: InferableEntityUseCase<T, TEntityReducers & EntityReducers<T>, TUseCaseOptions>, options?: UseCaseHookOptions<T, TUseCaseOptions>, deps?:
|
|
57
|
+
<T, TEntityReducers extends EntityReducerMap<T>, TUseCaseOptions extends object = object, TDependencies extends Dependencies = Dependencies>(entity: T | EntityGetter<T, TDependencies>, usecase: InferableEntityUseCase<T, TEntityReducers & EntityReducers<T>, TUseCaseOptions>, options?: UseCaseHookOptions<T, TUseCaseOptions>, deps?: TDependencies): RootCoreCollection<T, EntityReducers<T, TEntityReducers>>;
|
|
58
58
|
}
|
|
59
59
|
export interface CoreCollectionHook extends ContextualCoreCollectionHook, RootCoreCollectionHook {
|
|
60
60
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { createUseCase, entityUseCase } from '@mic-rexjs/usecases';
|
|
1
|
+
import { createUseCase, entityUseCase, utilsUseCase } from '@mic-rexjs/usecases';
|
|
2
2
|
export const valueUseCase = createUseCase(() => {
|
|
3
|
-
let keyIndex = 0;
|
|
4
3
|
return () => {
|
|
5
|
-
|
|
4
|
+
const { createKey } = utilsUseCase();
|
|
5
|
+
let prevKeyIndex = createKey();
|
|
6
6
|
const entityReducers = entityUseCase();
|
|
7
7
|
const hasField = (entity, field) => {
|
|
8
8
|
if (typeof entity !== 'object' || entity === null) {
|
|
@@ -13,7 +13,7 @@ export const valueUseCase = createUseCase(() => {
|
|
|
13
13
|
const isValueChanged = (entity, value) => {
|
|
14
14
|
return entity !== value;
|
|
15
15
|
};
|
|
16
|
-
const isValueMatched = (entity, value) => {
|
|
16
|
+
const isValueMatched = (entity, value, onMatchFailed) => {
|
|
17
17
|
if (entity === value) {
|
|
18
18
|
return true;
|
|
19
19
|
}
|
|
@@ -22,22 +22,39 @@ export const valueUseCase = createUseCase(() => {
|
|
|
22
22
|
if (!isObject1 || !isObject2) {
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
|
+
let allMatched = true;
|
|
25
26
|
const keys1 = Object.keys(entity);
|
|
26
27
|
const keys2 = Object.keys(value);
|
|
27
28
|
const { length: length1 } = keys1;
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
const keys = [...keys1, ...keys2];
|
|
30
|
+
const hasCallback = typeof onMatchFailed === 'function';
|
|
31
|
+
for (let i = 0, { length } = keys; i < length; i++) {
|
|
32
|
+
const key = keys[i];
|
|
33
|
+
const isFromKeys2 = i >= length1;
|
|
34
|
+
const isInKey1 = keys1.includes(key);
|
|
35
|
+
const isUsed = isFromKeys2 && isInKey1;
|
|
36
|
+
if (isUsed) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
const hasField1 = Object.hasOwn(entity, key);
|
|
40
|
+
const hasField2 = Object.hasOwn(value, key);
|
|
41
|
+
const onlyHasField1 = hasField1 && !hasField2;
|
|
42
|
+
const onlyHasField2 = !hasField1 && hasField2;
|
|
43
|
+
const onlyHasOneField = onlyHasField1 || onlyHasField2;
|
|
33
44
|
const value1 = entity[key];
|
|
34
45
|
const value2 = value[key];
|
|
35
|
-
|
|
46
|
+
const matched = value1 === value2;
|
|
47
|
+
if (!onlyHasOneField && matched) {
|
|
36
48
|
continue;
|
|
37
49
|
}
|
|
38
|
-
|
|
50
|
+
allMatched = false;
|
|
51
|
+
if (hasCallback) {
|
|
52
|
+
onMatchFailed(key, value2, value1);
|
|
53
|
+
continue;
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
39
56
|
}
|
|
40
|
-
return
|
|
57
|
+
return allMatched;
|
|
41
58
|
};
|
|
42
59
|
const matchProperty = (entity, value, fieldPath, onFailed) => {
|
|
43
60
|
let allMatched = true;
|
|
@@ -106,6 +123,24 @@ export const valueUseCase = createUseCase(() => {
|
|
|
106
123
|
yield value;
|
|
107
124
|
return true;
|
|
108
125
|
};
|
|
126
|
+
const recordValueDiff = function* (entity, value) {
|
|
127
|
+
const isArray1 = Array.isArray(entity);
|
|
128
|
+
const isArray2 = Array.isArray(value);
|
|
129
|
+
const isArray = isArray1 && isArray2;
|
|
130
|
+
const result = (isArray ? [] : {});
|
|
131
|
+
if (isArray) {
|
|
132
|
+
const { length: length1 } = entity;
|
|
133
|
+
const { length: length2 } = value;
|
|
134
|
+
result.length = Math.max(length1, length2);
|
|
135
|
+
}
|
|
136
|
+
const matched = isValueMatched(entity, value, (key, newValue) => {
|
|
137
|
+
result[key] = newValue;
|
|
138
|
+
});
|
|
139
|
+
if (!matched) {
|
|
140
|
+
yield value;
|
|
141
|
+
}
|
|
142
|
+
return result;
|
|
143
|
+
};
|
|
109
144
|
const recordValueMatch = function* (entity, value) {
|
|
110
145
|
const matched = isValueMatched(entity, value);
|
|
111
146
|
if (matched) {
|
|
@@ -114,12 +149,10 @@ export const valueUseCase = createUseCase(() => {
|
|
|
114
149
|
yield value;
|
|
115
150
|
return false;
|
|
116
151
|
};
|
|
117
|
-
const recordValueMatchWith = function* (entity, value, key
|
|
152
|
+
const recordValueMatchWith = function* (entity, value, key) {
|
|
118
153
|
const matched = yield* recordValueMatch(entity, value);
|
|
119
154
|
if (!matched) {
|
|
120
|
-
|
|
121
|
-
keyIndex++;
|
|
122
|
-
prevKeyIndex = key;
|
|
155
|
+
prevKeyIndex = key ?? createKey();
|
|
123
156
|
}
|
|
124
157
|
return prevKeyIndex;
|
|
125
158
|
};
|
|
@@ -129,6 +162,7 @@ export const valueUseCase = createUseCase(() => {
|
|
|
129
162
|
isValueMatched,
|
|
130
163
|
matchProperty,
|
|
131
164
|
recordValue,
|
|
165
|
+
recordValueDiff,
|
|
132
166
|
recordValueMatch,
|
|
133
167
|
recordValueMatchWith,
|
|
134
168
|
};
|
|
@@ -1,15 +1,20 @@
|
|
|
1
1
|
import { EntityGenerator, EntityReducers } from '@mic-rexjs/usecases';
|
|
2
|
+
import React from 'react';
|
|
2
3
|
import { MatchPropertyFailedResult } from '../../entities/matchPropertyFailedResult/types';
|
|
3
4
|
export interface MatchPropertyFailedCallback<T> {
|
|
4
5
|
(result: MatchPropertyFailedResult<T>): void;
|
|
5
6
|
}
|
|
7
|
+
export interface MatchValueFailedCallback<T> {
|
|
8
|
+
<K extends keyof T>(key: K, newValue: T[K], oldValue: T[K]): void;
|
|
9
|
+
}
|
|
6
10
|
export type ValueReducers<T> = EntityReducers<T, {
|
|
7
11
|
isValueChanged<S extends T>(entity: S, value: S): boolean;
|
|
8
|
-
isValueMatched<S extends T>(entity: S, value: S): boolean;
|
|
12
|
+
isValueMatched<S extends T>(entity: S, value: S, onMatchFailed?: MatchValueFailedCallback<S>): boolean;
|
|
9
13
|
matchProperty<S extends T>(entity: S, value: S, fieldPath: string, onFailed?: MatchPropertyFailedCallback<S>): boolean;
|
|
10
14
|
recordValue<S extends T>(entity: S, value: S): EntityGenerator<S, boolean>;
|
|
15
|
+
recordValueDiff<S extends T>(entity: S, value: S): EntityGenerator<S, Partial<S>>;
|
|
11
16
|
recordValueMatch<S extends T>(entity: S, value: S): EntityGenerator<S, boolean>;
|
|
12
|
-
recordValueMatchWith<S extends T>(entity: S, value: S, key?:
|
|
17
|
+
recordValueMatchWith<S extends T>(entity: S, value: S, key?: React.Key): EntityGenerator<S, React.Key>;
|
|
13
18
|
}>;
|
|
14
19
|
export interface ValueUseCase {
|
|
15
20
|
<T>(): ValueReducers<T>;
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useConstantReducers = void 0;
|
|
7
|
+
var _useConstant = require("../useConstant");
|
|
8
|
+
var useConstantReducers = exports.useConstantReducers = function useConstantReducers(usecase, options) {
|
|
9
|
+
return (0, _useConstant.useConstant)(function () {
|
|
10
|
+
return usecase(options);
|
|
11
|
+
});
|
|
12
|
+
};
|
|
@@ -4,15 +4,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.useContextualItem = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _useConstantReducers2 = require("../useConstantReducers");
|
|
8
|
+
var _useDepsKey = require("../useDepsKey");
|
|
8
9
|
var _ahooks = require("ahooks");
|
|
9
10
|
var _Statuses = require("../../enums/Statuses");
|
|
10
11
|
var _methodUseCase = require("../../usecases/methodUseCase");
|
|
11
12
|
var useContextualItem = exports.useContextualItem = function useContextualItem(contextItem, statuses, createFactory) {
|
|
12
|
-
var
|
|
13
|
+
var deps = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
|
|
14
|
+
var depsKey = (0, _useDepsKey.useDepsKey)(deps);
|
|
13
15
|
var factoryRef = (0, _ahooks.useLatest)(createFactory);
|
|
14
|
-
var
|
|
15
|
-
cacheCall =
|
|
16
|
+
var _useConstantReducers = (0, _useConstantReducers2.useConstantReducers)(_methodUseCase.methodUseCase),
|
|
17
|
+
cacheCall = _useConstantReducers.cacheCall;
|
|
16
18
|
var onCache = (0, _ahooks.useMemoizedFn)(function () {
|
|
17
19
|
var currentFactory = factoryRef.current;
|
|
18
20
|
void depsKey;
|
|
@@ -6,11 +6,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.useDepsKey = void 0;
|
|
8
8
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var
|
|
9
|
+
var _useConstantEntityReducers = require("../useConstantEntityReducers");
|
|
10
10
|
var _valueUseCase = require("../../usecases/valueUseCase");
|
|
11
11
|
var useDepsKey = exports.useDepsKey = function useDepsKey(deps) {
|
|
12
|
-
var
|
|
13
|
-
recordValueMatchWith =
|
|
12
|
+
var _useConstantEntityRed = (0, _useConstantEntityReducers.useConstantEntityReducers)(deps, _valueUseCase.valueUseCase),
|
|
13
|
+
recordValueMatchWith = _useConstantEntityRed.recordValueMatchWith;
|
|
14
14
|
var _recordValueMatchWith = recordValueMatchWith(deps),
|
|
15
15
|
_recordValueMatchWith2 = (0, _slicedToArray2["default"])(_recordValueMatchWith, 2),
|
|
16
16
|
depsKey = _recordValueMatchWith2[1];
|