@airma/react-state
Advanced tools
Comparing version 18.5.7 to 18.5.8
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("@airma/react-hooks-core")):"function"==typeof define&&define.amd?define(["react","@airma/react-hooks-core"],e):"object"==typeof exports?exports["@airma/react-state"]=e(require("react"),require("@airma/react-hooks-core")):t["@airma/react-state"]=e(t.react,t["@airma/react-hooks-core"])}(self,(function(t,e){return function(){"use strict";var n={309:function(t){t.exports=e},156:function(e){e.exports=t}},r={};function o(t){var e=r[t];if(void 0!==e)return e.exports;var c=r[t]={exports:{}};return n[t](c,c.exports,o),c.exports}o.d=function(t,e){for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var c={};return function(){function t(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 e(e,n){if(e){if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}function n(n){return function(e){if(Array.isArray(e))return t(e)}(n)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(n)||e(n)||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 r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t,n){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,c=[],u=!0,i=!1;try{for(n=n.call(t);!(u=(r=n.next()).done)&&(c.push(r.value),!e||c.length!==e);u=!0);}catch(t){i=!0,o=t}finally{try{u||null==n.return||n.return()}finally{if(i)throw o}}return c}}(t,n)||e(t,n)||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.")}()}o.r(c),o.d(c,{ConfigProvider:function(){return Q},Provider:function(){return q},createKey:function(){return N},model:function(){return X},provide:function(){return H},shallowEqual:function(){return J},useControlledModel:function(){return G},useModel:function(){return K},useSelector:function(){return B},useSignal:function(){return Y}});var i=o(156),a=o(309);function f(t){return f="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},f(t)}function s(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 l(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?s(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function d(t,e,n,r){var o=Object.keys(n),c={};return o.forEach((function(n){c[n]={get:function(){return r.get?r.get(t,n,e):t[n]},set:function(o){if(r.set){if(!r.set(t,n,o,e))throw new Error("".concat(n," in proxy target is not mutable"))}else t[n]=o}}})),c}var p=function(t,e){return"function"!=typeof Proxy?function(t,e){var n={},r=d(t,n,t,e),o=d(t,n,Object.getPrototypeOf(t),e);return Object.defineProperties(n,l(l({},o),r)),n}(t,e):new Proxy(t,e)};function v(t){return t&&"object"===f(t)}function h(t,e){if(Object.is(t,e))return!0;if(!v(t)||!v(e))return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;var o=t,c=e;return!n.some((function(t){return!Object.prototype.hasOwnProperty.call(c,t)}))&&!r.some((function(t){var e=c[t],n=o[t];return!Object.is(e,n)}))}function y(){}function g(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 b(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?g(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var m={},O="@@lazyIdentify";function S(t,e){t.forEach((function(t){t(e)}))}function j(t,e){return t(e)}function w(t,e){return function(r){if(null!=r){var o=t.dispatching;if(function(e){var n=t.dispatching;if(!n){var r={value:e};return r.tail=r,void(t.dispatching=r)}var o=n.tail;if(o){var c={prev:o,value:e};o.next=c,n.tail=c}}(r),!o){for(var c=function(){var r=t.dispatching;if(r){var o=n(t.dispatches);try{"function"==typeof e.batchUpdate&&o.length?e.batchUpdate((function(){S(o,r.value)})):S(o,r.value)}catch(e){throw t.dispatching=void 0,e}!function(){var e=t.dispatching;if(e){var n=e.next,r=e.tail;if(r===e||!n)return e.tail=void 0,t.dispatching=void 0,e;n.prev=void 0;var o=n;o.tail=r,t.dispatching=o}}()}else t.dispatching=void 0};t.dispatching;)c();!function(){var e=t.temporaryDispatches;e.length||(t.dispatches=t.dispatches.concat(e),t.temporaryDispatches=[]);var n={state:t.state,prevState:t.state,instance:t.current,prevInstance:t.current,type:"",method:null};e.forEach((function(t){t(n)}))}()}}}}function P(t,e,n){var r=t.current[e];if(r.noActionMethod&&r.noActionMethod===m)return r;if(n.methodsCache[e])return n.methodsCache[e];var o=function r(){for(var o=arguments.length,c=new Array(o),u=0;u<o;u++)c[u]=arguments[u];var i=t.current[e].apply(void 0,c),a=t.reducer,f=t.controlled;if(t.isDestroyed)return i;var s={type:e,state:i,prevState:i,instance:t.current,prevInstance:t.current,method:r};if(f)return t.notify(s),i;var l=t.state,d=t.current;t.current=j(a,i),t.state=i,t.version+=1,t.cacheState={state:i};var p={type:e,state:i,prevState:l,instance:t.current,prevInstance:d,method:r},v=n.middleWare?n.middleWare(p):p;return t.notify(v),i};return o.dispatchType=e,o.dispatchId=n.sourceTo,n.methodsCache[e]=o,o}function E(t,e){var n=t.current[e];if(!n||n.cacheGenerator!==E)return function(t,e){t.cacheGenerators[e]&&(t.cacheGenerators[e]=null)}(t,e),n;var r=t.cacheGenerators[e];if(r&&(n.deps&&h(r.deps,n.deps)||!n.deps&&r.value===n.value))return r.out;var o={get:function(){var n=t.current[e];if(null==n)throw new Error("This field is not exist now.");if(!D(n))throw new Error("This field is changed to be a normal object");var r=t.cacheGenerators[e];if(!r)return n.value;var o=r.value,c=r.deps;return n.deps&&h(c,n.deps)||!n.deps&&o===n.value?o:n.value}};return t.cacheGenerators[e]={value:n.value,deps:n.deps,out:o},o}function D(t){return!!t&&"object"===f(t)&&t.cacheGenerator===E}function C(t,e,r){var o=j(t,e),c=r||{},u=c.controlled,i={batchUpdate:c.batchUpdate},a={version:0,isDestroyed:!1,current:o,reducer:t,dispatch:null,dispatches:[],temporaryDispatches:[],cacheMethods:{},cacheGenerators:{},state:e,cacheState:null,controlled:!!u,notify:y,isSubscribing:!1};function f(t,e){var n=a.state;if(!a.isDestroyed){var r=!(!e||!e.isDefault),o=!(!e||!e.ignoreDispatch);if(!r||!a.cacheState){var c=e?e.state:n;c===n||a.controlled||(a.version+=1);var u=n,i=a.current;a.reducer=t,a.state=c,a.cacheState=e&&e.cache?{state:e.state}:a.cacheState,a.current=j(t,a.state),n===a.state||r||o||a.notify({state:a.state,prevState:u,instance:a.current,prevInstance:i,type:"",method:null})}}}function s(){if(!a.isDestroyed){for(var t={state:a.state,prevState:a.state,instance:a.current,prevInstance:a.current,type:"",method:null},e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];n.forEach((function(e){e(t)}))}}function l(t){var e=a.dispatches,r=a.temporaryDispatches,o=a.controlled;a.isDestroyed||([].concat(n(e),n(r)).indexOf(t)>=0||(o?a.dispatches=[t]:(a.temporaryDispatches.push(t),a.dispatching||(a.dispatches=[].concat(n(a.dispatches),n(a.temporaryDispatches)),a.temporaryDispatches=[],s.apply(void 0,n(r))))))}function d(t){if(!t)return a.dispatches=[],void(a.temporaryDispatches=[]);var e=a.dispatches,n=a.temporaryDispatches;a.dispatches=e.filter((function(e){return e!==t})),a.temporaryDispatches=n.filter((function(e){return e!==t}))}a.notify=w(a,i);var v=p(o,{get:function(t,e){var n=a.current[e];return D(n)?n.cacheGenerator(a,e):Object.prototype.hasOwnProperty.call(a.current,e)&&"function"==typeof n?P(a,e,{methodsCache:a.cacheMethods}):n}});return{agent:v,getReducer:function(){return a.reducer},getCacheState:function(){return a.cacheState},getState:function(){return a.state},getVersion:function(){return a.version},getCurrent:function(t){if(a.isDestroyed)return a.current;if(Array.isArray(a.current))return a.current.map((function(e,n){return D(e)?e.cacheGenerator(a,n.toString()):"function"==typeof e?t?P(a,n.toString(),b(b({},t),{},{sourceTo:v[n]})):v[n]:e}));var e=Object.keys(a.current),n=b({},a.current);return e.forEach((function(e){var r=n[e];D(r)?n[e]=r.cacheGenerator(a,e):"function"==typeof r&&(n[e]=t?P(a,e,b(b({},t),{},{sourceTo:v[e]})):v[e])})),n},getStoreInstance:function(){return a.current},getListeners:function(){return a.dispatches},update:f,updateState:function(t){f(a.reducer,{state:t,cache:!0})},notice:function(){s(a.notify)},tunnel:function(t){return{connect:function(){l(t)},disconnect:function(){d(t)}}},destroy:function(){a.dispatch=null,a.dispatches=[],function(t){var e=t.dispatching;if(e){for(var n=e;n;){var r=n.next;n.next=void 0,n.prev=void 0,r&&(r.prev=void 0),n=r}e.tail=void 0,t.dispatching=void 0}}(a),a.temporaryDispatches=[],a.notify=y,a.isDestroyed=!0,a.cacheMethods={},a.cacheGenerators={},i.batchUpdate=void 0},renew:function(t){if(a.isDestroyed=!1,a.notify=w(a,i),t){var e=t.getState,n=t.getReducer;a.cacheState=null,f(n(),{state:e(),ignoreDispatch:!0})}},connect:function(t){l(t)},disconnect:d,optimize:function(t){i.batchUpdate!==t&&(i.batchUpdate=void 0,i.batchUpdate=t)},isDestroyed:function(){return a.isDestroyed},setPayload:function(t){var e=t(a.payload);return a.payload=e,e},getPayload:function(){return a.payload}}}function x(t){if(t.agent[O])throw new Error("A stateless connection should be initialized before it is accessed.")}function k(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if("function"==typeof t&&"function"==typeof t.creation)return[{key:r.join("."),keys:r,factory:t,connection:t.creation(e)}];if(!t||"object"!==f(t))return[];var o=[],c=t;return Object.keys(c).forEach((function(t){var u=k(c[t],e,r.concat(t));o.push.apply(o,n(u))})),o}function A(t){return{get:function(e){var n=t.find((function(t){return t.factory===e||t.sourceFactory===e}));return n?n.connection:void 0}}}function M(t,e){var n,r,o=k(t,e),c=(r=(n=o).map((function(t){return t.connection})),{collections:n,connections:r,instances:A(n)}),u={destroyed:!1,parent:null==e?void 0:e.parent,update:function(n,r){return n!==t||(null==r?void 0:r.parent)!==(null==e?void 0:e.parent)||u.destroyed?(u.parent=r?r.parent:void 0,function(t,e){var n=k(t,e),r=c.collections,o=A(n);r.forEach((function(t){null!=o.get(t.factory)&&t.connection.renew()}))}(n),u.destroyed=!1,u):u},get:function(t){return c.instances.get(t)},destroy:function(){c.connections.forEach((function(t){return t.destroy()})),u.destroyed=!0}};return u}function R(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 U(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?R(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):R(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var I=(0,i.createContext)(void 0);function F(t){var e=(0,i.useRef)(null);return null==e.current?(e.current={result:t()},e.current.result):e.current.result}function G(t,e,n){return function(t,e,n,r){var o=(r||{}).disabled,c=C(t,e,{controlled:!0}),u=(0,a.usePersistFn)((function(t){var r=t.state;e!==r&&(o||n(r))})),f=c.tunnel(u);return(0,i.useEffect)((function(){return f.connect(),function(){f.disconnect()}})),(0,i.useEffect)((function(){return c.renew(),function(){c.destroy()}}),[]),c.getCurrent()}(t,e,n)}var T=(0,i.createContext)(null);function W(){var t=((0,i.useContext)(I)||{}).batchUpdate;return(0,i.useMemo)((function(){return{batchUpdate:t}}),[t])}var q=function(t){var e=t.keys,n=t.value,r=t.children,o=null!=e?e:n;if(null==o)throw new Error("You need to provide keys to `Provider`");var c=W().batchUpdate,u=(0,i.useContext)(T),a=F((function(){return M(o,{batchUpdate:c,parent:u||void 0})}));return(0,i.useEffect)((function(){return a.update(o,{batchUpdate:c,parent:u||void 0}),function(){a.destroy()}}),[a,o,u]),(0,i.createElement)(T.Provider,{value:a},r)};function z(t,e){if(e.connection)return e.connection;if(null!=t){var n=t.get(e);return!n&&t.parent?z(t.parent,e):n}}function V(){var t=(0,i.useRef)({}),e=(0,a.usePersistFn)((function(t){return t}));return{methodsCache:t.current,middleWare:e}}function L(t,e,n){var r=U(U({},{required:!1}),n),o=r.useDefaultState,c=r.signal,f=(0,i.useRef)(!1),s=(0,i.useRef)(!1),l=(0,i.useRef)(!1);s.current=!1,f.current=!1;var d=W().batchUpdate,v=(0,i.useRef)(!1),g=(0,i.useContext)(T),b=t.isFactory,m="function"==typeof b&&b(),O=m?z(g,t):void 0;if(m&&!O)throw new Error("The model in usage is a `store key`, it should match with a store created by `StoreProvider`.");var S=null!=O&&!!o&&null==O.getCacheState();S&&O.update(t,{state:e,cache:!0,ignoreDispatch:!0}),null!=O&&x(O);var j=V(),w=(0,i.useRef)(t),P=F((function(){return O||C(t,e)})),E=F((function(){return!!O}));P.optimize(d);var D=O||P;w.current===t||O||(w.current=t,D.update(t));var k=u((0,i.useState)({agent:D.getCurrent(j),action:null}),2),A=k[0],M=k[1],R=(0,i.useRef)(D.getVersion()),I=(0,i.useRef)(null),G=A.agent,q={selection:[]};I.current=q.selection;var L=(0,a.usePersistFn)((function(t){var e=t;if(!v.current){var n,r,o,u,i=D.getVersion(),a=D.getCurrent(j);if(R.current!==i||e.payload)if(e.payload||(R.current=i),!c||s.current)if(!(c&&I.current&&(n=a,r=G,o=I.current,u=!0,o.forEach((function(t){n[t]!==r[t]&&(u=!1)})),u)))M({agent:a,action:e})}}));(0,i.useLayoutEffect)((function(){f.current=!0,l.current=s.current}));var _=D.tunnel(L);(0,i.useEffect)((function(){return _.connect(),function(){_.disconnect()}})),(0,i.useEffect)((function(){return v.current=!1,D.renew(),function(){v.current=!0,I.current=null,E||D.destroy()}}),[]),(0,i.useEffect)((function(){S&&D.notice()}),[S]);var K=function(){s.current=!0,q.selection!==I.current&&(q.selection=null);var t=D.getCurrent(j);return p(t,{get:function(t,e,n){var r=t[e];if(null!=q.selection&&q.selection===I.current&&!v.current&&!f.current){var o={};q.selection.forEach((function(t){o[t]=!0})),o[e]||q.selection.push(e)}return r}})},Y=(0,a.usePersistFn)(K),$=l.current?K:Y,B=function(t,e){function n(t){return null==t?null:t.dispatchId||t}return{useEffectWrap:function(r){var o=(0,i.useRef)(null),c=(0,i.useRef)(null),f=(0,i.useRef)(null),s=u((0,i.useState)(null),2),l=s[0],d=s[1],p=V(),v=(0,a.usePersistFn)((function(e){if(l!==e&&e.type){var r=t.getCurrent(p),u=o.current,i=f.current;if(null!=u||null!=i){var a=c.current,s=i?i(r):null;c.current=s,u&&u.length&&u.map(n).indexOf(n(e.method))<0||null!=s&&null!=a&&h(s,a)||d(e)}}})),g=t.tunnel(v);(0,i.useEffect)((function(){if(null==o.current&&null==f.current)return y;if(null!=o.current&&null==l)return y;var e=t.getCurrent(p);return r(e,l)}),[l]),(0,i.useEffect)((function(){if(null!=o.current||null!=f.current)return y;var n=t.getCurrent(p);return r(n,e)}),[e]),(0,i.useEffect)((function(){return g.connect(),function(){g.disconnect()}}),[]);var b={onActions:function(e){var n=e(t.getCurrent(p));if(!Array.isArray(n))throw new Error("The `filter callback` for method `on` should return an action method array.");return o.current=n.filter((function(t){return"function"==typeof t})),b},onChanges:function(t){return f.current=t,b}};return b},useWatchtWrap:function(e){var r=(0,i.useRef)(null),o=(0,i.useRef)(null),c=(0,i.useRef)(null),u=V(),f=(0,a.usePersistFn)((function(i){if(!i.type)return y;var a=t.getCurrent(u),f=r.current,s=c.current,l=o.current,d=s?s(a):null;return o.current=d,f&&f.length&&f.map(n).indexOf(n(i.method))<0||null!=d&&null!=l&&h(d,l)?y:e(a,i)})),s=t.tunnel(f);(0,i.useEffect)((function(){return s.connect(),function(){s.disconnect()}}),[]);var l={onActions:function(e){var n=e(t.getCurrent(u));if(!Array.isArray(n))throw new Error("The `filter callback` for method `on` should return an action method array.");return r.current=n.filter((function(t){return"function"==typeof t})),l},onChanges:function(t){return c.current=t,l}};return l},getConnection:function(){return{isDestroyed:function(){return t.isDestroyed()},setPayload:function(e){return t.setPayload(e)},getPayload:function(){return t.getPayload()}}}}}(D,A.action),H=B.useEffectWrap,J=B.useWatchtWrap,N=B.getConnection;$.useEffect=H,$.useWatch=J,$.getConnection=N;var Q=G;if(c)return[D.getState(),Q,D.updateState,$];return[D.getState(),Q,D.updateState,function(){return Q}]}function _(t,e,n){var r=u(L(t,e,n),4),o=r[0],c=r[1];r[2];return[o,c,r[3]]}function K(t,e){return u(_(t,e,{useDefaultState:arguments.length>1}),2)[1]}function Y(t,e){return u(_(t,e,{useDefaultState:arguments.length>1,signal:!0}),3)[2]}var $=function(t){return'API "'.concat(t,'" can not work, there is no matched Provider with its store key.')};function B(t,e,n){var r=W().batchUpdate,o=(0,i.useContext)(T),c=V(),f=z(o,t);if(!f)throw new Error($("useSelector"));x(f),f.optimize(r);var s=e(f.getCurrent(c)),l=(0,i.useRef)(!1),d=(0,i.useRef)(f.getVersion()),p=u((0,i.useState)({data:s}),2),v=p[0],h=p[1],y=(0,a.usePersistFn)((function(){if(!l.current){var t=f.getVersion();if(d.current!==t){d.current=t;var r=e(f.getCurrent(c));(function(t,e){return n?n(t,e):Object.is(t,e)})(v.data,r)||h({data:r})}}})),g=f.tunnel(y);return(0,i.useEffect)((function(){return g.connect(),function(){g.disconnect()}})),(0,i.useEffect)((function(){return l.current=!1,function(){l.current=!0}}),[]),v.data}function H(t){return function(e){return function(n){return(0,i.createElement)(q,{value:t},(0,i.createElement)(e,n))}}}var J=h,N=function(t,e){return function(t,e,n){var o=function(e){return t(e)};return o.creation=function(t){return n?C((function(t){return r({},O,m)}),void 0,t):C(o,e,t)},o.static=function(){return function(t){var e=function(e){return t(e)};return e.payload=t.payload,e.connection=t.creation(),e.static=function(){return e},e.isFactory=t.isFactory,e}(o)},o.isFactory=function(){return!0},o}(t,e,arguments.length<2)},Q=function(t){var e=t.value,n=t.children;return(0,i.createElement)(I.Provider,{value:e},n)},X=function(t){var e=function(e){return t(e)};e.meta={};var r=function t(r,o){var c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],u=null!=o?o:arguments.length>0?N(e,r):N(e);var a={key:u,keys:c,useModel:function(t){var e=arguments.length?[u,t]:[u];return K.apply(void 0,e)},useSignal:function(t){var e=arguments.length?[u,t]:[u];return Y.apply(void 0,e)},useSelector:function(t,e){return B(u,t,e)},static:function(){var t=u.static();return{useModel:function(e){var n=arguments.length?[t,e]:[t];return K.apply(void 0,n)},useSignal:function(e){var n=arguments.length?[t,e]:[t];return Y.apply(void 0,n)},useSelector:function(e,n){return B(t,e,n)}}},provide:function(){return H([u].concat(n(c)))},provideTo:function(t){return H([u].concat(n(c)))(t)},Provider:function(t){var e=t.children;return(0,i.createElement)(q,{value:[u].concat(n(c))},e)}};return U(U({},a),{},{with:function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=c.concat(n.map((function(t){return"function"==typeof t?t:t.key})));return t(r,u,i)}})};return Object.assign(e,{useModel:function(t){var n=arguments.length?[e,t]:[e];return K.apply(void 0,n)},useSignal:function(t){var n=arguments.length?[e,t]:[e];return Y.apply(void 0,n)},useControlledModel:function(t,n){return G(e,t,n)},createStore:function(t){return arguments.length?r(t):r()}})};X.create=X,X.createCacheField=function(t,e){var n=null==e?e:e.some((function(t){return D(t)&&null==t.deps}))?void 0:e.flatMap((function(t){return D(t)?t.deps:t})),r=t();return{callback:t,deps:n,cacheGenerator:E,value:r,get:function(){return r}}},X.createField=function(t,e){var n=null==e?e:e.some((function(t){return D(t)&&null==t.deps}))?void 0:e.flatMap((function(t){return D(t)?t.deps:t})),r=t();return{callback:t,deps:n,cacheGenerator:E,value:r,get:function(){return r}}},X.createMethod=function(t){var e=function(){return t.apply(void 0,arguments)};return Object.assign(e,t),e.noActionMethod=m,e}}(),c}()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("react"),require("@airma/react-hooks-core")):"function"==typeof define&&define.amd?define(["react","@airma/react-hooks-core"],e):"object"==typeof exports?exports["@airma/react-state"]=e(require("react"),require("@airma/react-hooks-core")):t["@airma/react-state"]=e(t.react,t["@airma/react-hooks-core"])}(self,(function(t,e){return function(){"use strict";var n={309:function(t){t.exports=e},156:function(e){e.exports=t}},r={};function o(t){var e=r[t];if(void 0!==e)return e.exports;var c=r[t]={exports:{}};return n[t](c,c.exports,o),c.exports}o.d=function(t,e){for(var n in e)o.o(e,n)&&!o.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var c={};return function(){function t(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 e(e,n){if(e){if("string"==typeof e)return t(e,n);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?t(e,n):void 0}}function n(n){return function(e){if(Array.isArray(e))return t(e)}(n)||function(t){if("undefined"!=typeof Symbol&&null!=t[Symbol.iterator]||null!=t["@@iterator"])return Array.from(t)}(n)||e(n)||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 r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function u(t,n){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,c=[],u=!0,i=!1;try{for(n=n.call(t);!(u=(r=n.next()).done)&&(c.push(r.value),!e||c.length!==e);u=!0);}catch(t){i=!0,o=t}finally{try{u||null==n.return||n.return()}finally{if(i)throw o}}return c}}(t,n)||e(t,n)||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.")}()}o.r(c),o.d(c,{ConfigProvider:function(){return Q},Provider:function(){return z},createKey:function(){return N},model:function(){return X},provide:function(){return H},shallowEqual:function(){return J},useControlledModel:function(){return G},useModel:function(){return _},useSelector:function(){return B},useSignal:function(){return Y}});var i=o(156),a=o(309);function f(t){return f="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},f(t)}function s(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 l(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?s(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):s(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}function d(t,e,n,r){var o=Object.keys(n),c={};return o.forEach((function(n){c[n]={get:function(){return r.get?r.get(t,n,e):t[n]},set:function(o){if(r.set){if(!r.set(t,n,o,e))throw new Error("".concat(n," in proxy target is not mutable"))}else t[n]=o}}})),c}var p=function(t,e){return"function"!=typeof Proxy?function(t,e){var n={},r=d(t,n,t,e),o=d(t,n,Object.getPrototypeOf(t),e);return Object.defineProperties(n,l(l({},o),r)),n}(t,e):new Proxy(t,e)};function v(t){return t&&"object"===f(t)}function h(t,e){if(Object.is(t,e))return!0;if(!v(t)||!v(e))return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;var o=t,c=e;return!n.some((function(t){return!Object.prototype.hasOwnProperty.call(c,t)}))&&!r.some((function(t){var e=c[t],n=o[t];return!Object.is(e,n)}))}function y(){}function g(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 b(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?g(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):g(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var m={},O="@@lazyIdentify";function S(t,e){t.forEach((function(t){t(e)}))}function j(t,e){return t(e)}function w(t,e){return function(r){if(null!=r){var o=t.dispatching;if(function(e){var n=t.dispatching;if(!n){var r={value:e};return r.tail=r,void(t.dispatching=r)}var o=n.tail;if(o){var c={prev:o,value:e};o.next=c,n.tail=c}}(r),!o){for(var c=function(){var r=t.dispatching;if(r){var o=n(t.dispatches);try{"function"==typeof e.batchUpdate&&o.length?e.batchUpdate((function(){S(o,r.value)})):S(o,r.value)}catch(e){throw t.dispatching=void 0,e}!function(){var e=t.dispatching;if(e){var n=e.next,r=e.tail;if(r===e||!n)return e.tail=void 0,t.dispatching=void 0,e;n.prev=void 0;var o=n;o.tail=r,t.dispatching=o}}()}else t.dispatching=void 0};t.dispatching;)c();!function(){var e=t.temporaryDispatches;e.length||(t.dispatches=t.dispatches.concat(e),t.temporaryDispatches=[]);var n={state:t.state,prevState:t.state,instance:t.current,prevInstance:t.current,type:"",method:null};e.forEach((function(t){t(n)}))}()}}}}function P(t,e,n){var r=t.current[e];if(r.noActionMethod&&r.noActionMethod===m)return r;if(n.methodsCache[e])return n.methodsCache[e];var o=function r(){for(var o=arguments.length,c=new Array(o),u=0;u<o;u++)c[u]=arguments[u];var i=t.current[e].apply(void 0,c),a=t.reducer,f=t.controlled;if(t.isDestroyed)return i;var s={type:e,state:i,prevState:i,instance:t.current,prevInstance:t.current,method:r};if(f)return t.notify(s),i;var l=t.state,d=t.current;t.current=j(a,i),t.state=i,t.version+=1,t.cacheState={state:i};var p={type:e,state:i,prevState:l,instance:t.current,prevInstance:d,method:r},v=n.middleWare?n.middleWare(p):p;return t.notify(v),i};return o.dispatchType=e,o.dispatchId=n.sourceTo,n.methodsCache[e]=o,o}function E(t,e){var n=t.current[e];if(!n||n.cacheGenerator!==E)return function(t,e){t.cacheGenerators[e]&&(t.cacheGenerators[e]=null)}(t,e),n;var r=t.cacheGenerators[e];if(r&&(n.deps&&h(r.deps,n.deps)||!n.deps&&r.value===n.value))return r.out;var o={get:function(){var n=t.current[e];if(null==n)throw new Error("This field is not exist now.");if(!D(n))throw new Error("This field is changed to be a normal object");var r=t.cacheGenerators[e];if(!r)return n.value;var o=r.value,c=r.deps;return n.deps&&h(c,n.deps)||!n.deps&&o===n.value?o:n.value}};return t.cacheGenerators[e]={value:n.value,deps:n.deps,out:o},o}function D(t){return!!t&&"object"===f(t)&&t.cacheGenerator===E}function C(t,e,r){var o=j(t,e),c=r||{},u=c.controlled,i={batchUpdate:c.batchUpdate},a={version:0,isDestroyed:!1,current:o,reducer:t,dispatch:null,dispatches:[],temporaryDispatches:[],cacheMethods:{},cacheGenerators:{},state:e,cacheState:null,controlled:!!u,notify:y,isSubscribing:!1};function f(t,e){var n=a.state;if(!a.isDestroyed){var r=!(!e||!e.isDefault),o=!(!e||!e.ignoreDispatch);if(!r||!a.cacheState){var c=e?e.state:n;c===n||a.controlled||(a.version+=1);var u=n,i=a.current;a.reducer=t,a.state=c,a.cacheState=e&&e.cache?{state:e.state}:a.cacheState,a.current=j(t,a.state),n===a.state||r||o||a.notify({state:a.state,prevState:u,instance:a.current,prevInstance:i,type:"",method:null})}}}function s(){if(!a.isDestroyed){for(var t={state:a.state,prevState:a.state,instance:a.current,prevInstance:a.current,type:"",method:null},e=arguments.length,n=new Array(e),r=0;r<e;r++)n[r]=arguments[r];n.forEach((function(e){e(t)}))}}function l(t){var e=a.dispatches,r=a.temporaryDispatches,o=a.controlled;a.isDestroyed||([].concat(n(e),n(r)).indexOf(t)>=0||(o?a.dispatches=[t]:(a.temporaryDispatches.push(t),a.dispatching||(a.dispatches=[].concat(n(a.dispatches),n(a.temporaryDispatches)),a.temporaryDispatches=[],s.apply(void 0,n(r))))))}function d(t){if(!t)return a.dispatches=[],void(a.temporaryDispatches=[]);var e=a.dispatches,n=a.temporaryDispatches;a.dispatches=e.filter((function(e){return e!==t})),a.temporaryDispatches=n.filter((function(e){return e!==t}))}a.notify=w(a,i);var v=p(o,{get:function(t,e){var n=a.current[e];return D(n)?n.cacheGenerator(a,e):Object.prototype.hasOwnProperty.call(a.current,e)&&"function"==typeof n?P(a,e,{methodsCache:a.cacheMethods}):n}});return{agent:v,getReducer:function(){return a.reducer},getCacheState:function(){return a.cacheState},getState:function(){return a.state},getVersion:function(){return a.version},getCurrent:function(t){if(a.isDestroyed)return a.current;if(Array.isArray(a.current))return a.current.map((function(e,n){return D(e)?e.cacheGenerator(a,n.toString()):"function"==typeof e?t?P(a,n.toString(),b(b({},t),{},{sourceTo:v[n]})):v[n]:e}));var e=Object.keys(a.current),n=b({},a.current);return e.forEach((function(e){var r=n[e];D(r)?n[e]=r.cacheGenerator(a,e):"function"==typeof r&&(n[e]=t?P(a,e,b(b({},t),{},{sourceTo:v[e]})):v[e])})),n},getStoreInstance:function(){return a.current},getListeners:function(){return a.dispatches},update:f,updateState:function(t){f(a.reducer,{state:t,cache:!0})},notice:function(){s(a.notify)},tunnel:function(t){return{connect:function(){l(t)},disconnect:function(){d(t)}}},destroy:function(){a.dispatch=null,a.dispatches=[],function(t){var e=t.dispatching;if(e){for(var n=e;n;){var r=n.next;n.next=void 0,n.prev=void 0,r&&(r.prev=void 0),n=r}e.tail=void 0,t.dispatching=void 0}}(a),a.temporaryDispatches=[],a.notify=y,a.isDestroyed=!0,a.cacheMethods={},a.cacheGenerators={},i.batchUpdate=void 0},renew:function(t){if(a.isDestroyed=!1,a.notify=w(a,i),t){var e=t.getState,n=t.getReducer;a.cacheState=null,f(n(),{state:e(),ignoreDispatch:!0})}},connect:function(t){l(t)},disconnect:d,optimize:function(t){i.batchUpdate!==t&&(i.batchUpdate=void 0,i.batchUpdate=t)},isDestroyed:function(){return a.isDestroyed},setPayload:function(t){var e=t(a.payload);return a.payload=e,e},getPayload:function(){return a.payload}}}function x(t){if(t.agent[O])throw new Error("A stateless connection should be initialized before it is accessed.")}function k(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if("function"==typeof t&&"function"==typeof t.creation)return[{key:r.join("."),keys:r,factory:t,connection:t.creation(e)}];if(!t||"object"!==f(t))return[];var o=[],c=t;return Object.keys(c).forEach((function(t){var u=k(c[t],e,r.concat(t));o.push.apply(o,n(u))})),o}function A(t){return{get:function(e){var n=t.find((function(t){return t.factory===e||t.sourceFactory===e}));return n?n.connection:void 0}}}function M(t,e){var n,r,o=k(t,e),c=(r=(n=o).map((function(t){return t.connection})),{collections:n,connections:r,instances:A(n)}),u={destroyed:!1,parent:null==e?void 0:e.parent,update:function(n,r){return n!==t||(null==r?void 0:r.parent)!==(null==e?void 0:e.parent)||u.destroyed?(u.parent=r?r.parent:void 0,function(t,e){var n=k(t,e),r=c.collections,o=A(n);r.forEach((function(t){null!=o.get(t.factory)&&t.connection.renew()}))}(n),u.destroyed=!1,u):u},get:function(t){return c.instances.get(t)},destroy:function(){c.connections.forEach((function(t){return t.destroy()})),u.destroyed=!0}};return u}function R(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 I(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?R(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):R(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var U=(0,i.createContext)(void 0);function F(t){var e=(0,i.useRef)(null);return null==e.current?(e.current={result:t()},e.current.result):e.current.result}function G(t,e,n){return function(t,e,n,r){var o=(r||{}).disabled,c=C(t,e,{controlled:!0}),u=(0,a.usePersistFn)((function(t){var r=t.state;e!==r&&(o||n(r))})),f=c.tunnel(u);return(0,i.useEffect)((function(){return f.connect(),function(){f.disconnect()}})),(0,i.useEffect)((function(){return c.renew(),function(){c.destroy()}}),[]),c.getCurrent()}(t,e,n)}var T=(0,i.createContext)(null);function W(){var t=((0,i.useContext)(U)||{}).batchUpdate;return(0,i.useMemo)((function(){return{batchUpdate:t}}),[t])}var z=function(t){var e=t.keys,n=t.value,r=t.children,o=null!=e?e:n;if(null==o)throw new Error("You need to provide keys to `Provider`");var c=W().batchUpdate,u=(0,i.useContext)(T),a=F((function(){return M(o,{batchUpdate:c,parent:u||void 0})}));return(0,i.useEffect)((function(){return a.update(o,{batchUpdate:c,parent:u||void 0}),function(){a.destroy()}}),[a,o,u]),(0,i.createElement)(T.Provider,{value:a},r)};function q(t,e){if(e.connection)return e.connection;if(null!=t){var n=t.get(e);return!n&&t.parent?q(t.parent,e):n}}function V(){var t=(0,i.useRef)({}),e=(0,a.usePersistFn)((function(t){return t}));return{methodsCache:t.current,middleWare:e}}function K(t,e,n){var r=I(I({},{required:!1}),n),o=r.useDefaultState,c=r.signal,f=(0,i.useRef)(!1),s=(0,i.useRef)(!1),l=(0,i.useRef)(!1);s.current=!1,f.current=!1;var d=W().batchUpdate,v=(0,i.useRef)(!1),g=(0,i.useContext)(T),b=t.isFactory,m="function"==typeof b&&b(),O=m?q(g,t):void 0;if(m&&!O)throw new Error("The model in usage is a `store key`, it should match with a store created by `StoreProvider`.");var S=null!=O&&!!o&&null==O.getCacheState();S&&O.update(t,{state:e,cache:!0,ignoreDispatch:!0}),null!=O&&x(O);var j=V(),w=(0,i.useRef)(t),P=F((function(){return O||C(t,e)})),E=F((function(){return!!O}));P.optimize(d);var D=O||P;w.current===t||O||(w.current=t,D.update(t));var k=u((0,i.useState)({agent:D.getCurrent(j),action:null}),2),A=k[0],M=k[1],R=(0,i.useRef)(D.getVersion()),U=(0,i.useRef)(null),G=A.agent,z={selection:[]};U.current=z.selection;var K=(0,a.usePersistFn)((function(t){var e=t;if(!v.current){var n,r,o,u,i=D.getVersion(),a=D.getCurrent(j);if(R.current!==i||e.payload)if(e.payload||(R.current=i),!c||s.current)if(!(c&&U.current&&(n=a,r=G,o=U.current,u=!0,o.forEach((function(t){n[t]!==r[t]&&(u=!1)})),u)))M({agent:a,action:e})}}));(0,i.useLayoutEffect)((function(){f.current=!0,l.current=s.current}));var L=D.tunnel(K);(0,i.useEffect)((function(){return L.connect(),function(){L.disconnect()}})),(0,i.useEffect)((function(){return v.current=!1,D.renew(),function(){v.current=!0,U.current=null,E||D.destroy()}}),[]),(0,i.useEffect)((function(){S&&D.notice()}),[S]);var _=function(){s.current=!0,z.selection!==U.current&&(z.selection=null);var t=D.getCurrent(j);return p(t,{get:function(t,e,n){var r=t[e];if(null!=z.selection&&z.selection===U.current&&!v.current&&!f.current){var o={};z.selection.forEach((function(t){o[t]=!0})),o[e]||z.selection.push(e)}return r}})},Y=(0,a.usePersistFn)(_),$=l.current?_:Y,B=function(t,e){function n(t){return null==t?null:t.dispatchId||t}return{useEffectWrap:function(r){var o=(0,i.useRef)(null),c=(0,i.useRef)(null),f=(0,i.useRef)(null),s=u((0,i.useState)(null),2),l=s[0],d=s[1],p=V(),v=(0,a.usePersistFn)((function(e){if(l!==e&&e.type){var r=t.getCurrent(p),u=o.current,i=f.current;if(null!=u||null!=i){var a=c.current,s=i?i(r):null;c.current=s,u&&u.length&&u.map(n).indexOf(n(e.method))<0||null!=s&&null!=a&&h(s,a)||d(e)}}})),g=t.tunnel(v);(0,i.useEffect)((function(){if(null==o.current&&null==f.current)return y;if(null!=o.current&&null==l)return y;var e=t.getCurrent(p);return r(e,l)}),[l]),(0,i.useEffect)((function(){if(null!=o.current||null!=f.current)return y;var n=t.getCurrent(p);return r(n,e)}),[e]),(0,i.useEffect)((function(){return g.connect(),function(){g.disconnect()}}),[]);var b={onActions:function(e){var n=e(t.getCurrent(p));if(!Array.isArray(n))throw new Error("The `filter callback` for method `on` should return an action method array.");return o.current=n.filter((function(t){return"function"==typeof t})),b},onChanges:function(t){return f.current=t,b}};return b},useWatchtWrap:function(e){var r=(0,i.useRef)(null),o=(0,i.useRef)(null),c=(0,i.useRef)(null),u=V(),f=(0,a.usePersistFn)((function(i){if(!i.type)return y;var a=t.getCurrent(u),f=r.current,s=c.current,l=o.current,d=s?s(a):null;return o.current=d,f&&f.length&&f.map(n).indexOf(n(i.method))<0||null!=d&&null!=l&&h(d,l)?y:e(a,i)})),s=t.tunnel(f);(0,i.useEffect)((function(){return s.connect(),function(){s.disconnect()}}),[]);var l={onActions:function(e){var n=e(t.getCurrent(u));if(!Array.isArray(n))throw new Error("The `filter callback` for method `on` should return an action method array.");return r.current=n.filter((function(t){return"function"==typeof t})),l},onChanges:function(t){return c.current=t,l}};return l},getConnection:function(){return{isDestroyed:function(){return t.isDestroyed()},setPayload:function(e){return t.setPayload(e)},getPayload:function(){return t.getPayload()}}}}}(D,A.action),H=B.useEffectWrap,J=B.useWatchtWrap,N=B.getConnection;$.useEffect=H,$.useWatch=J,$.getConnection=N;var Q=G;if(c)return[D.getState(),Q,D.updateState,$];return[D.getState(),Q,D.updateState,function(){return Q}]}function L(t,e,n){var r=u(K(t,e,n),4),o=r[0],c=r[1];r[2];return[o,c,r[3]]}function _(t,e){return u(L(t,e,{useDefaultState:arguments.length>1}),2)[1]}function Y(t,e){return u(L(t,e,{useDefaultState:arguments.length>1,signal:!0}),3)[2]}var $=function(t){return'API "'.concat(t,'" can not work, there is no matched Provider with its store key.')};function B(t,e,n){var r=W().batchUpdate,o=(0,i.useContext)(T),c=V(),f=q(o,t);if(!f)throw new Error($("useSelector"));x(f),f.optimize(r);var s=e(f.getCurrent(c)),l=(0,i.useRef)(!1),d=(0,i.useRef)(f.getVersion()),p=u((0,i.useState)({data:s}),2),v=p[0],h=p[1],y=(0,a.usePersistFn)((function(){if(!l.current){var t=f.getVersion();if(d.current!==t){d.current=t;var r=e(f.getCurrent(c));(function(t,e){return n?n(t,e):Object.is(t,e)})(v.data,r)||h({data:r})}}})),g=f.tunnel(y);return(0,i.useEffect)((function(){return g.connect(),function(){g.disconnect()}})),(0,i.useEffect)((function(){return l.current=!1,function(){l.current=!0}}),[]),v.data}function H(t){return function(e){return function(n){return(0,i.createElement)(z,{value:t},(0,i.createElement)(e,n))}}}var J=h,N=function(t,e){return function(t,e,n){var o=function(e){return t(e)};return o.creation=function(t){return n?C((function(t){return r({},O,m)}),void 0,t):C(o,e,t)},o.static=function(){return function(t){var e=function(e){return t(e)};return e.payload=t.payload,e.connection=t.creation(),e.static=function(){return e},e.isFactory=t.isFactory,e.getInstance=function(){return e.connection.getCurrent()},e.initialize=function(n){var r=e.connection;null!=r&&null==r.getCacheState()&&r.update(t,{state:n,cache:!0,ignoreDispatch:!0})},e}(o)},o.isFactory=function(){return!0},o}(t,e,arguments.length<2)},Q=function(t){var e=t.value,n=t.children;return(0,i.createElement)(U.Provider,{value:e},n)},X=function(t){var e=function(e){return t(e)};e.meta={};var r=function t(r,o){var c=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],u=null!=o?o:arguments.length>0?N(e,r):N(e);function a(){var t=u.static();return{useModel:function(e){var n=arguments.length?[t,e]:[t];return _.apply(void 0,n)},useSignal:function(e){var n=arguments.length?[t,e]:[t];return Y.apply(void 0,n)},useSelector:function(e,n){return B(t,e,n)},getInstance:t.getInstance,initialize:t.initialize}}var f={key:u,keys:c,useModel:function(t){var e=arguments.length?[u,t]:[u];return _.apply(void 0,e)},useSignal:function(t){var e=arguments.length?[u,t]:[u];return Y.apply(void 0,e)},useSelector:function(t,e){return B(u,t,e)},static:a,provide:function(){return H([u].concat(n(c)))},provideTo:function(t){return H([u].concat(n(c)))(t)},Provider:function(t){var e=t.children;return(0,i.createElement)(z,{value:[u].concat(n(c))},e)},createStore:a};return I(I({},f),{},{with:function(){for(var e=arguments.length,n=new Array(e),o=0;o<e;o++)n[o]=arguments[o];var i=c.concat(n.map((function(t){return"function"==typeof t?t:t.key})));return t(r,u,i)}})};function o(t){return arguments.length?r(t):r()}return Object.assign(e,{useModel:function(t){var n=arguments.length?[e,t]:[e];return _.apply(void 0,n)},useSignal:function(t){var n=arguments.length?[e,t]:[e];return Y.apply(void 0,n)},useControlledModel:function(t,n){return G(e,t,n)},createStore:o,createKey:o})};X.create=X,X.createCacheField=function(t,e){var n=null==e?e:e.some((function(t){return D(t)&&null==t.deps}))?void 0:e.flatMap((function(t){return D(t)?t.deps:t})),r=t();return{callback:t,deps:n,cacheGenerator:E,value:r,get:function(){return r}}},X.createField=function(t,e){var n=null==e?e:e.some((function(t){return D(t)&&null==t.deps}))?void 0:e.flatMap((function(t){return D(t)?t.deps:t})),r=t();return{callback:t,deps:n,cacheGenerator:E,value:r,get:function(){return r}}},X.createMethod=function(t){var e=function(){return t.apply(void 0,arguments)};return Object.assign(e,t),e.noActionMethod=m,e}}(),c}()})); |
@@ -64,2 +64,6 @@ import { FunctionComponent, FC, NamedExoticComponent, ReactNode } from 'react'; | ||
export interface KeyIndex { | ||
key: any; | ||
} | ||
export declare function useModel<R extends AirReducer>( | ||
@@ -148,9 +152,9 @@ model: ModelKey<R> | ||
| { | ||
[key: string]: ModelKey<AirReducer> | ModelKeys | StoreApi<AirReducer>; | ||
[key: string]: ModelKey<any> | ModelKeys | KeyIndex; | ||
} | ||
| { | ||
[key: number]: ModelKey<AirReducer> | ModelKeys | StoreApi<AirReducer>; | ||
[key: number]: ModelKey<any> | ModelKeys | KeyIndex; | ||
} | ||
| ModelKey<AirReducer> | ||
| StoreApi<AirReducer>; | ||
| ModelKey<any> | ||
| KeyIndex; | ||
@@ -229,5 +233,7 @@ export declare const Provider: FC< | ||
) => ReturnType<C>; | ||
getInstance: () => ValidReducerReturnType<R>; | ||
initialize: (state: PickState<R>) => void; | ||
} | ||
declare interface StoreApi<R extends AirReducer> extends StoreUsageApi<R> { | ||
declare interface StoreApi<R extends AirReducer> extends KeyIndex { | ||
key: ModelKey<R>; | ||
@@ -237,3 +243,7 @@ with: <M extends ModelKey<AirReducer>>( | ||
) => StoreApi<R>; | ||
/** | ||
* @deprecated | ||
*/ | ||
static: () => StoreUsageApi<R>; | ||
createStore: () => StoreUsageApi<R>; | ||
provide: <P>() => ( | ||
@@ -246,2 +256,8 @@ component: FunctionComponent<P> | NamedExoticComponent<P> | ||
Provider: FC<{ children?: ReactNode }>; | ||
useModel: (state?: PickState<R>) => ValidReducerReturnType<R>; | ||
useSignal: (state?: PickState<R>) => SignalHandler<R>; | ||
useSelector: <C extends (instance: ReturnType<R>) => any>( | ||
call: C, | ||
equalFn?: (c: ReturnType<C>, n: ReturnType<C>) => boolean | ||
) => ReturnType<C>; | ||
} | ||
@@ -253,3 +269,8 @@ | ||
useControlledModel: ControlledModelUsage<R>; | ||
/** | ||
* @deprecated | ||
* @param state | ||
*/ | ||
createStore: (state?: PickState<R>) => StoreApi<R>; | ||
createKey: (state?: PickState<R>) => StoreApi<R>; | ||
} | ||
@@ -256,0 +277,0 @@ |
{ | ||
"name": "@airma/react-state", | ||
"version": "18.5.7", | ||
"version": "18.5.8", | ||
"description": "the purpose of this project is make useReducer more simplify", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -0,0 +0,0 @@ [![npm][npm-image]][npm-url] |
40795
260