@mic-rexjs/usecases-react 2.3.1 → 2.3.2

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 CHANGED
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see index.min.js.LICENSE.txt */
2
- (()=>{var t={20:(t,e,n)=>{"use strict";var r=n(594),o=Symbol.for("react.element"),u=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};e.jsx=function(t,e,n){var r,l={},c=null,f=null;for(r in void 0!==n&&(c=""+n),void 0!==e.key&&(c=""+e.key),void 0!==e.ref&&(f=e.ref),e)u.call(e,r)&&!i.hasOwnProperty(r)&&(l[r]=e[r]);if(t&&t.defaultProps)for(r in e=t.defaultProps)void 0===l[r]&&(l[r]=e[r]);return{$$typeof:o,type:t,key:c,ref:f,props:l,_owner:a.current}}},848:(t,e,n)=>{"use strict";t.exports=n(20)},594:t=>{"use strict";t.exports=React}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var u=e[r]={exports:{}};return t[r](u,u.exports,n),u.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};(()=>{"use strict";n.r(r),n.d(r,{UseCaseFragment:()=>A,useStatelessUseCase:()=>M,useUseCase:()=>x});var t=n(848),e=n(594),o=n.n(e);function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function a(t,e){if(t){if("string"==typeof t)return u(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,e):void 0}}function i(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,o,u,a,i=[],l=!0,c=!1;try{if(u=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=u.call(n)).done)&&(i.push(r.value),i.length!==e);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw o}}return i}}(t,e)||a(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=ahooks;var c,f=function(t){return i((0,e.useState)((function(){return t})),1)[0]};function s(t){return s="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},s(t)}function y(t){var e=function(t,e){if("object"!=s(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=s(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:String(e)}!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=22]="ContextRootEnabled",t[t.EntityRootEnabled=62]="EntityRootEnabled",t[t.StatelessEnabled=72]="StatelessEnabled"}(c||(c={}));const d=usecases;var b=["watch","onChange","options"];function v(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function E(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?v(Object(n),!0).forEach((function(e){var r,o,u;r=t,o=e,u=n[e],(o=y(o))in r?Object.defineProperty(r,o,{value:u,enumerable:!0,configurable:!0,writable:!0}):r[o]=u})):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 p,m=function(t){return i((0,e.useState)(t),1)[0]},h=new Map;!function(t){t[t.None=0]="None",t[t.Entity=2]="Entity",t[t.Mode=4]="Mode"}(p||(p={}));var S,g=(0,e.createContext)(null);!function(t){t[t.Normal=2]="Normal",t[t.Stateless=4]="Stateless"}(S||(S={}));var O=function(t,e){var n=t.length;if(n!==e.length)return!1;for(var r=0;r<n;r++)if(t[r]!==e[r])return!1;return!0},w=function(t,e){var n,r=e||{},o=r.onShouldCache,u=void 0===o?function(){return!0}:o,a=r.onCompare,i=void 0===a?function(t,e){return O(t,e)}:a;return function(){for(var e=u(),r=arguments.length,o=new Array(r),a=0;a<r;a++)o[a]=arguments[a];if(n&&e){var l=n,c=l.parameters,f=l.returnValue;if(i(c,o))return f}var s=t.apply(void 0,o);return e&&(n={parameters:o,returnValue:s}),s}},j=function(t,n,r){var o,u,a,i=(o=r,u=function(t){var n=(0,e.useRef)(0),r=(0,e.useRef)([]),o=r.current,u=O(t,o);return r.current=t,n.current+=u?0:1,n.current}(arguments.length>3&&void 0!==arguments[3]?arguments[3]:[]),a=(0,l.useLatest)(o),(0,l.useCreation)((function(){return w(a.current,{onCompare:function(){return!0}})}),[u,a]));return(0,l.useCreation)((function(){return(n&c.RootEnabled)!==c.RootEnabled&&t?t:i()}),[n,t,i])};function C(t){return function(t){if(Array.isArray(t))return u(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||a(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 R=function(t,e){return"object"===s(t)&&null!==t&&Object.hasOwn(t,e)},P=function t(e,n,r,o){var u=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],a=void 0,l=i(r.match(/^([^.]+)\.(.+)$/)||[],3),c=l[1],f=void 0===c?r:c,s=l[2],y=void 0===s?"":s,d=R(e,f),b=R(n,f),v=[].concat(C(u),[f]);if(d||b){var E=d?e[f]:a,p=b?n[f]:a;if(y)return void t(E,p,y,o,v);if(E===p)return;o(E,p,v)}else if(!/^\d+^/.test(f))for(var m=Array.isArray(e)?e:[],h=Array.isArray(n)?n:[],S=m.length,g=h.length,O=Math.max(S,g),w=0;w<O;w++)t(m[w],h[w],r,o,[].concat(C(u),["".concat(w)]))},_=function(t,e,n){for(var r=function(){var t=i(u[o],2),r=t[0],a=t[1];P(n,e,r,(function(t,r,o){a({fieldPaths:o,newEntity:e,oldEntity:n,newValue:r,oldValue:t})}))},o=0,u=Object.entries(t);o<u.length;o++)r()},x=function(){for(var t,n=((t=(0,e.useRef)(!0)).current=!0,(0,e.useEffect)((function(){t.current=!1})),t),r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var y=function(t){return m((function(){var e=p.None,n=i(t,3),r=n[1],o=n[2];return"function"===s(r)&&(e|=p.Entity,"number"==typeof o&&(e|=p.Mode)),e}))}(u),v=function(t,e){var n=i(t,5),r=n[0],o=n[1],u=n[2],a=n[3],l=n[4],c=(e&p.Entity)===p.Entity,f=(e&p.Mode)===p.Mode;return c?f?[r,o,u,a||{},l||[]]:[r,o,S.Normal,u||{},a||[]]:[null,r,S.Normal,o||{},u||[]]}(u,y),O=i(v,5),C=O[0],R=O[1],P=O[2],x=O[3],A=O[4],M=f(R),N=M,I=M,T=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p.None,r=h,o=m((function(){if(r.has(t)){var o=r.get(t),u=o.value,a=o.times;return r.set(t,{value:u,times:a+1}),u}if((n&p.Entity)!==p.Entity)return g;var i=(0,e.createContext)(null);return r.set(t,{value:i,times:1}),i}));return(0,l.useUnmount)((function(){if(r.has(t)){var e=r.get(t),n=e.value,u=e.times;o===n&&(1!==u?r.set(t,{value:n,times:u-1}):r.delete(t))}})),o}(M,y),k=(0,e.useContext)(T),U=k,D=function(t,e,n){return(0,l.useCreation)((function(){var r=c.None,o=(n||{}).store;return(t&p.Entity)===p.Entity&&(r|=c.EntityRootEnabled),r|=n?c.ContextEnabled:c.RootEnabled,o&&(r|=c.EntityEnabled),(e&S.Stateless)===S.Stateless&&(r|=c.StatelessEnabled),r}),[t,n,e])}(y,P,k),L=(k||{}).reducers,V=void 0===L?null:L,$=(U||{}).store,F=i(function(t,n,r,o){var u=i((0,e.useState)(n),2),a=u[0],f=u[1],s=r?r.value:null,y=function(t,e,n,r){return(t&c.EntityRootEnabled)!==c.EntityRootEnabled?r:(t&c.StatelessEnabled)!==c.StatelessEnabled?e:"function"==typeof n?n():n}(t,a,n,s),b=(0,l.useLatest)(o),v=(t&c.EntityRootEnabled)===c.EntityRootEnabled,E=j(r,t,(function(){if(!v)return new d.EntityStore(null);var e=(t&c.StatelessEnabled)===c.StatelessEnabled;return new d.EntityStore(y,{onChange:function(t){e||f(t)}})}));return v&&(E.value=y),(0,e.useEffect)((function(){if((t&c.EntityEnabled)===c.EntityEnabled){var e=function(t,e){var n=b.current,r=n.onChange,o=n.watch;o&&_(o,t,e),null==r||r(t,e)};return E.watch(e),function(){E.unwatch(e)}}}),[t,E,b]),(0,l.useCreation)((function(){return[y,E]}),[y,E])}(D,C,void 0===$?null:$,x),2),B=F[0],G=F[1],W=j(V,D,(function(){return(D&c.EntityEnabled)!==c.EntityEnabled?N(x):function(t,e,n){n.watch,n.onChange;var r=n.options,o=function(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},u=Object.keys(t);for(r=0;r<u.length;r++)n=u[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(t);for(r=0;r<u.length;r++)n=u[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}(n,b);return(0,d.createEntityReducers)(e,t,E(E(E({},o),r),{},{onGenerate:function(t,e){return e}}))}(I,G,x)}),A),Y=function(t,n,r,u){var a=r.value,i=(0,e.useMemo)((function(){return(t&c.EntityEnabled)===c.EntityEnabled?{store:r,reducers:u,statuses:t}:{reducers:u,statuses:t}}),[t,a,r,u]),s=(0,l.useLatest)(i);return f((function(t){var e=t.children,r=t.with,u=void 0===r?[]:r,a=n.Provider;return o().createElement(a,{value:s.current},u.reduceRight((function(t,e){return o().createElement(e,{},t)}),e))}))}(D,T,G,W);return(0,l.useCreation)((function(){if((D&c.EntityEnabled)!==c.EntityEnabled)return W;var t=(D&c.RootEnabled)===c.RootEnabled,e=function(t,e){var n={};return Object.entries(t).forEach((function(t){var r=i(t,2),o=r[0],u=r[1];n[o]=w(u,e)})),n}(W,{onShouldCache:function(){return n.current}});return t?[B,e,Y]:[B,e]}),[D,B,W,Y,n])},A=function(n){var r=n.usecase,o=n.watch,u=n.onChange;return x(r,{watch:o,onChange:u}),(0,t.jsx)(e.Fragment,{})},M=function(t,e,n,r){return x(t,e,S.Stateless,n,r)}})();var o=usecases="undefined"==typeof usecases?{}:usecases;for(var u in r)o[u]=r[u];r.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})})();
2
+ (()=>{var t={20:(t,e,n)=>{"use strict";var r=n(594),o=Symbol.for("react.element"),u=(Symbol.for("react.fragment"),Object.prototype.hasOwnProperty),a=r.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,i={key:!0,ref:!0,__self:!0,__source:!0};e.jsx=function(t,e,n){var r,l={},c=null,f=null;for(r in void 0!==n&&(c=""+n),void 0!==e.key&&(c=""+e.key),void 0!==e.ref&&(f=e.ref),e)u.call(e,r)&&!i.hasOwnProperty(r)&&(l[r]=e[r]);if(t&&t.defaultProps)for(r in e=t.defaultProps)void 0===l[r]&&(l[r]=e[r]);return{$$typeof:o,type:t,key:c,ref:f,props:l,_owner:a.current}}},848:(t,e,n)=>{"use strict";t.exports=n(20)},594:t=>{"use strict";t.exports=React}},e={};function n(r){var o=e[r];if(void 0!==o)return o.exports;var u=e[r]={exports:{}};return t[r](u,u.exports,n),u.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};(()=>{"use strict";n.r(r),n.d(r,{UseCaseFragment:()=>A,useStatelessUseCase:()=>M,useUseCase:()=>x});var t=n(848),e=n(594),o=n.n(e);function u(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function a(t,e){if(t){if("string"==typeof t)return u(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?u(t,e):void 0}}function i(t,e){return function(t){if(Array.isArray(t))return t}(t)||function(t,e){var n=null==t?null:"undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(null!=n){var r,o,u,a,i=[],l=!0,c=!1;try{if(u=(n=n.call(t)).next,0===e){if(Object(n)!==n)return;l=!1}else for(;!(l=(r=u.call(n)).done)&&(i.push(r.value),i.length!==e);l=!0);}catch(t){c=!0,o=t}finally{try{if(!l&&null!=n.return&&(a=n.return(),Object(a)!==a))return}finally{if(c)throw o}}return i}}(t,e)||a(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=ahooks;var c,f=function(t){return i((0,e.useState)((function(){return t})),1)[0]};function s(t){return s="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},s(t)}function y(t){var e=function(t,e){if("object"!=s(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=s(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==s(e)?e:String(e)}!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=22]="ContextRootEnabled",t[t.EntityRootEnabled=62]="EntityRootEnabled",t[t.StatelessEnabled=72]="StatelessEnabled"}(c||(c={}));const d=usecases;var b=["watch","onChange","options"];function v(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function E(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?v(Object(n),!0).forEach((function(e){var r,o,u;r=t,o=e,u=n[e],(o=y(o))in r?Object.defineProperty(r,o,{value:u,enumerable:!0,configurable:!0,writable:!0}):r[o]=u})):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 p,m=function(t){return i((0,e.useState)(t),1)[0]},h=new Map;!function(t){t[t.None=0]="None",t[t.Entity=2]="Entity",t[t.Mode=4]="Mode"}(p||(p={}));var S,g=(0,e.createContext)(null);!function(t){t[t.Normal=2]="Normal",t[t.Stateless=4]="Stateless"}(S||(S={}));var O=function(t,e){var n=t.length;if(n!==e.length)return!1;for(var r=0;r<n;r++)if(t[r]!==e[r])return!1;return!0},w=function(t,e){var n,r=e||{},o=r.onShouldCache,u=void 0===o?function(){return!0}:o,a=r.onCompare,i=void 0===a?function(t,e){return O(t,e)}:a;return function(){for(var e=u(),r=arguments.length,o=new Array(r),a=0;a<r;a++)o[a]=arguments[a];if(n&&e){var l=n,c=l.parameters,f=l.returnValue;if(i(c,o))return f}var s=t.apply(void 0,o);return e&&(n={parameters:o,returnValue:s}),s}},j=function(t,e,n){var r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:0,o=(0,l.useLatest)(n),u=(0,l.useCreation)((function(){return w(o.current,{onCompare:function(){return!0}})}),[r,o]);return(0,l.useCreation)((function(){return(e&c.RootEnabled)!==c.RootEnabled&&t?t:u()}),[e,t,u])};function C(t){return function(t){if(Array.isArray(t))return u(t)}(t)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(t)||a(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 R=function(t,e){return"object"===s(t)&&null!==t&&Object.hasOwn(t,e)},P=function t(e,n,r,o){var u=arguments.length>4&&void 0!==arguments[4]?arguments[4]:[],a=void 0,l=i(r.match(/^([^.]+)\.(.+)$/)||[],3),c=l[1],f=void 0===c?r:c,s=l[2],y=void 0===s?"":s,d=R(e,f),b=R(n,f),v=[].concat(C(u),[f]);if(d||b){var E=d?e[f]:a,p=b?n[f]:a;if(y)return void t(E,p,y,o,v);if(E===p)return;o(E,p,v)}else if(!/^\d+^/.test(f))for(var m=Array.isArray(e)?e:[],h=Array.isArray(n)?n:[],S=m.length,g=h.length,O=Math.max(S,g),w=0;w<O;w++)t(m[w],h[w],r,o,[].concat(C(u),["".concat(w)]))},_=function(t,e,n){for(var r=function(){var t=i(u[o],2),r=t[0],a=t[1];P(n,e,r,(function(t,r,o){a({fieldPaths:o,newEntity:e,oldEntity:n,newValue:r,oldValue:t})}))},o=0,u=Object.entries(t);o<u.length;o++)r()},x=function(){for(var t,n=((t=(0,e.useRef)(!0)).current=!0,(0,e.useEffect)((function(){t.current=!1})),t),r=arguments.length,u=new Array(r),a=0;a<r;a++)u[a]=arguments[a];var y=function(t){return m((function(){var e=p.None,n=i(t,3),r=n[1],o=n[2];return"function"===s(r)&&(e|=p.Entity,"number"==typeof o&&(e|=p.Mode)),e}))}(u),v=function(t,e){var n=i(t,5),r=n[0],o=n[1],u=n[2],a=n[3],l=n[4],c=(e&p.Entity)===p.Entity,f=(e&p.Mode)===p.Mode;return c?f?[r,o,u,a||{},l||[]]:[r,o,S.Normal,u||{},a||[]]:[null,r,S.Normal,o||{},u||[]]}(u,y),C=i(v,5),R=C[0],P=C[1],x=C[2],A=C[3],M=C[4],N=f(P),I=N,T=N,k=function(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p.None,r=h,o=m((function(){if(r.has(t)){var o=r.get(t),u=o.value,a=o.times;return r.set(t,{value:u,times:a+1}),u}if((n&p.Entity)!==p.Entity)return g;var i=(0,e.createContext)(null);return r.set(t,{value:i,times:1}),i}));return(0,l.useUnmount)((function(){if(r.has(t)){var e=r.get(t),n=e.value,u=e.times;o===n&&(1!==u?r.set(t,{value:n,times:u-1}):r.delete(t))}})),o}(N,y),U=(0,e.useContext)(k),D=U,L=function(t,e,n){return(0,l.useCreation)((function(){var r=c.None,o=(n||{}).store;return(t&p.Entity)===p.Entity&&(r|=c.EntityRootEnabled),r|=n?c.ContextEnabled:c.RootEnabled,o&&(r|=c.EntityEnabled),(e&S.Stateless)===S.Stateless&&(r|=c.StatelessEnabled),r}),[t,n,e])}(y,x,U),F=function(t){var n=(0,e.useRef)(0),r=(0,e.useRef)([]),o=r.current,u=O(t,o);return r.current=t,n.current+=u?0:1,n.current}(M),V=(U||{}).reducers,$=void 0===V?null:V,z=(D||{}).store,B=i(function(t,n,r,o,u){var a=i((0,e.useState)(n),2),f=a[0],s=a[1],y=r?r.value:null,b=function(t,e,n,r){return(t&c.EntityRootEnabled)!==c.EntityRootEnabled?r:(t&c.StatelessEnabled)!==c.StatelessEnabled?e:"function"==typeof n?n():n}(t,f,n,y),v=(t&c.EntityEnabled)===c.EntityEnabled,E=(t&c.EntityRootEnabled)===c.EntityRootEnabled,p=j(r,t,(function(){if(!E)return new d.EntityStore(null);var e=(t&c.StatelessEnabled)===c.StatelessEnabled;return new d.EntityStore(b,{onChange:function(t){e||s(t)}})})),m=(0,l.useMemoizedFn)((function(){var t=o.onChange,e=o.watch,n=function(n,r){e&&_(e,n,r),null==t||t(n,r)};return p.watch(n),function(){p.unwatch(n)}}));return E&&(p.value=b),(0,e.useEffect)((function(){if(v)return m()}),[v,p,u,m]),(0,l.useCreation)((function(){return[b,p]}),[b,p])}(L,R,void 0===z?null:z,A,F),2),G=B[0],W=B[1],Y=j($,L,(function(){return(L&c.EntityEnabled)!==c.EntityEnabled?I(A):function(t,e,n){n.watch,n.onChange;var r=n.options,o=function(t,e){if(null==t)return{};var n,r,o=function(t,e){if(null==t)return{};var n,r,o={},u=Object.keys(t);for(r=0;r<u.length;r++)n=u[r],e.indexOf(n)>=0||(o[n]=t[n]);return o}(t,e);if(Object.getOwnPropertySymbols){var u=Object.getOwnPropertySymbols(t);for(r=0;r<u.length;r++)n=u[r],e.indexOf(n)>=0||Object.prototype.propertyIsEnumerable.call(t,n)&&(o[n]=t[n])}return o}(n,b);return(0,d.createEntityReducers)(e,t,E(E(E({},o),r),{},{onGenerate:function(t,e){return e}}))}(T,W,A)}),F),q=function(t,n,r,u){var a=r.value,i=(0,e.useMemo)((function(){return(t&c.EntityEnabled)===c.EntityEnabled?{store:r,reducers:u,statuses:t}:{reducers:u,statuses:t}}),[t,a,r,u]),s=(0,l.useLatest)(i);return f((function(t){var e=t.children,r=t.with,u=void 0===r?[]:r,a=n.Provider;return o().createElement(a,{value:s.current},u.reduceRight((function(t,e){return o().createElement(e,{},t)}),e))}))}(L,k,W,Y);return(0,l.useCreation)((function(){if((L&c.EntityEnabled)!==c.EntityEnabled)return Y;var t=(L&c.RootEnabled)===c.RootEnabled,e=function(t,e){var n={};return Object.entries(t).forEach((function(t){var r=i(t,2),o=r[0],u=r[1];n[o]=w(u,e)})),n}(Y,{onShouldCache:function(){return n.current}});return t?[G,e,q]:[G,e]}),[L,G,Y,q,n])},A=function(n){var r=n.usecase,o=n.watch,u=n.onChange;return x(r,{watch:o,onChange:u}),(0,t.jsx)(e.Fragment,{})},M=function(t,e,n,r){return x(t,e,S.Stateless,n,r)}})();var o=usecases="undefined"==typeof usecases?{}:usecases;for(var u in r)o[u]=r[u];r.__esModule&&Object.defineProperty(o,"__esModule",{value:!0})})();
@@ -1 +1 @@
1
- export declare const useCompareDeps: <T>(deps: T[]) => React.Key;
1
+ export declare const useCompareDeps: <T>(deps: T[]) => number;
@@ -1,3 +1,3 @@
1
1
  import { UseCaseStatuses } from '../../enums/UseCaseStatuses';
2
2
  import { CreateContextualItemFactory } from './types';
3
- export declare const useContextualItem: <T>(contextItem: T | null, statuses: UseCaseStatuses, createFactory: CreateContextualItemFactory<T>, deps?: unknown[]) => T;
3
+ export declare const useContextualItem: <T>(contextItem: T | null, statuses: UseCaseStatuses, createFactory: CreateContextualItemFactory<T>, depsKey?: number) => T;
@@ -1,8 +1,16 @@
1
- import { useCreation } from 'ahooks';
1
+ import { useCreation, useLatest } from 'ahooks';
2
2
  import { UseCaseStatuses } from '../../enums/UseCaseStatuses';
3
- import { useMemoizedCall } from '../useMemoizedCall';
4
- export const useContextualItem = (contextItem, statuses, createFactory, deps = []) => {
5
- const create = useMemoizedCall(createFactory, deps);
3
+ import { cacheCall } from '../../methods/cacheCall';
4
+ export const useContextualItem = (contextItem, statuses, createFactory, depsKey = 0) => {
5
+ const factoryRef = useLatest(createFactory);
6
+ const create = useCreation(() => {
7
+ void depsKey;
8
+ return cacheCall(factoryRef.current, {
9
+ onCompare() {
10
+ return true;
11
+ },
12
+ });
13
+ }, [depsKey, factoryRef]);
6
14
  return useCreation(() => {
7
15
  const rootEnabled = (statuses & UseCaseStatuses.RootEnabled) === UseCaseStatuses.RootEnabled;
8
16
  if (!rootEnabled && contextItem) {
@@ -1,4 +1,4 @@
1
1
  import { EntityStore } from '@mic-rexjs/usecases';
2
2
  import { UseCaseStatuses } from '../../enums/UseCaseStatuses';
3
3
  import { EntityGetter, UseCaseHookOptions } from '../useUseCase/types';
4
- export declare const useEntity: <T, TUseCaseOptions extends object, TOptions extends UseCaseHookOptions<T, TUseCaseOptions> = UseCaseHookOptions<T, TUseCaseOptions>>(statuses: UseCaseStatuses, rootEntity: T | EntityGetter<T>, contextStore: EntityStore<T> | null, options: TOptions) => [entity: T, store: EntityStore<T>];
4
+ export declare const useEntity: <T, TUseCaseOptions extends object, TOptions extends UseCaseHookOptions<T, TUseCaseOptions> = UseCaseHookOptions<T, TUseCaseOptions>>(statuses: UseCaseStatuses, rootEntity: T | EntityGetter<T>, contextStore: EntityStore<T> | null, options: TOptions, depsKey: number) => [entity: T, store: EntityStore<T>];
@@ -3,13 +3,13 @@ import { EntityStore } from '@mic-rexjs/usecases';
3
3
  import { UseCaseStatuses } from '../../enums/UseCaseStatuses';
4
4
  import { getRenderingEntity } from '../../methods/getRenderingEntity';
5
5
  import { useContextualItem } from '../useContextualItem';
6
- import { useCreation, useLatest } from 'ahooks';
6
+ import { useCreation, useMemoizedFn } from 'ahooks';
7
7
  import { triggerWatchers } from '../../methods/triggerWatchers';
8
- export const useEntity = (statuses, rootEntity, contextStore, options) => {
8
+ export const useEntity = (statuses, rootEntity, contextStore, options, depsKey) => {
9
9
  const [entityState, setEntityState] = useState(rootEntity);
10
10
  const contextEntity = (contextStore ? contextStore.value : null);
11
11
  const renderingEntity = getRenderingEntity(statuses, entityState, rootEntity, contextEntity);
12
- const optionsRef = useLatest(options);
12
+ const entityEnabled = (statuses & UseCaseStatuses.EntityEnabled) === UseCaseStatuses.EntityEnabled;
13
13
  const entityRootEnabled = (statuses & UseCaseStatuses.EntityRootEnabled) === UseCaseStatuses.EntityRootEnabled;
14
14
  const store = useContextualItem(contextStore, statuses, () => {
15
15
  if (!entityRootEnabled) {
@@ -25,16 +25,9 @@ export const useEntity = (statuses, rootEntity, contextStore, options) => {
25
25
  },
26
26
  });
27
27
  });
28
- if (entityRootEnabled) {
29
- // 执行同步操作
30
- store.value = renderingEntity;
31
- }
32
- useEffect(() => {
33
- if ((statuses & UseCaseStatuses.EntityEnabled) !== UseCaseStatuses.EntityEnabled) {
34
- return;
35
- }
28
+ const rewatch = useMemoizedFn(() => {
29
+ const { onChange, watch } = options;
36
30
  const onEntityChange = (newEntity, oldEntity) => {
37
- const { onChange, watch } = optionsRef.current;
38
31
  if (watch) {
39
32
  triggerWatchers(watch, newEntity, oldEntity);
40
33
  }
@@ -44,7 +37,17 @@ export const useEntity = (statuses, rootEntity, contextStore, options) => {
44
37
  return () => {
45
38
  store.unwatch(onEntityChange);
46
39
  };
47
- }, [statuses, store, optionsRef]);
40
+ });
41
+ if (entityRootEnabled) {
42
+ // 执行同步操作
43
+ store.value = renderingEntity;
44
+ }
45
+ useEffect(() => {
46
+ if (!entityEnabled) {
47
+ return;
48
+ }
49
+ return rewatch();
50
+ }, [entityEnabled, store, depsKey, rewatch]);
48
51
  return useCreation(() => {
49
52
  return [renderingEntity, store];
50
53
  }, [renderingEntity, store]);
@@ -12,6 +12,7 @@ import { UseCaseStatuses } from '../../enums/UseCaseStatuses';
12
12
  import { useEntity } from '../useEntity';
13
13
  import { useContextualItem } from '../useContextualItem';
14
14
  import { cacheCalls } from '../../methods/cacheCalls';
15
+ import { useCompareDeps } from '../useCompareDeps';
15
16
  export const useUseCase = ((...args) => {
16
17
  const isRenderingRef = useIsRenderingRef();
17
18
  const argumentTypes = useArgumentTypes(args);
@@ -24,16 +25,17 @@ export const useUseCase = ((...args) => {
24
25
  const contextValue = useContext(context);
25
26
  const entityContextValue = contextValue;
26
27
  const statuses = useUseCaseStatuses(argumentTypes, mode, contextValue);
28
+ const depsKey = useCompareDeps(deps);
27
29
  const { reducers: contextReducers = null } = contextValue || {};
28
30
  const { store: contextStore = null } = entityContextValue || {};
29
- const [entity, store] = useEntity(statuses, unsafeEntity, contextStore, options);
31
+ const [entity, store] = useEntity(statuses, unsafeEntity, contextStore, options, depsKey);
30
32
  const reducers = useContextualItem(contextReducers, statuses, () => {
31
33
  if ((statuses & UseCaseStatuses.EntityEnabled) !== UseCaseStatuses.EntityEnabled) {
32
34
  return usecase(options);
33
35
  }
34
36
  const hookOptions = options;
35
37
  return initEntityReducers(entityUseCase, store, hookOptions);
36
- }, deps);
38
+ }, depsKey);
37
39
  const Provider = useProvider(statuses, context, store, reducers);
38
40
  return useCreation(() => {
39
41
  if ((statuses & UseCaseStatuses.EntityEnabled) !== UseCaseStatuses.EntityEnabled) {