New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@airma/react-state

Package Overview
Dependencies
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@airma/react-state - npm Package Compare versions

Comparing version

to
18.3.0

2

dist/index.js

@@ -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(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.")}()}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(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.")}()}o.r(c),o.d(c,{ConfigProvider:function(){return X},ModelProvider:function(){return L},Provider:function(){return U},StoreProvider:function(){return _},createKey:function(){return W},model:function(){return Z},provide:function(){return H},shallowEqual:function(){return Q},useControlledModel:function(){return R},useIsModelMatchedInStore:function(){return N},useModel:function(){return V},useRealtimeInstance:function(){return J},useRefresh:function(){return z},useRefreshModel:function(){return Y},useSelector:function(){return B}});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 p(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 d=function(t,e){return"function"!=typeof Proxy?function(t,e){var n={},r=p(t,n,t,e),o=p(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 y(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 h(t){var e={};return t.forEach((function(t){var r=n(t,2),o=r[0],c=r[1];e[o]=c})),{get:function(t){return e[t]}}}function g(){}function b(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 m(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?b(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):b(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var O={},j="@@lazyIdentify";function w(t,e){t.forEach((function(t){t(e)}))}var S={context:null};function P(t,e,n){n.start(),S.context=n.context;var r=t(e);return S.context=null,n.end(),r[j]===O&&n.reset(),r}function k(t,e){return function(n){var r=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,c={prev:o,value:e};o.next=c,n.tail=c}(n),!r)for(var o=function(){var n=function(){var e=t.dispatching;if(e){var n=e.next,r=e.tail;if(r===e||!n)return t.dispatching=void 0,e;n.prev=void 0;var o=n;return o.tail=r,t.dispatching=o,e}}();if(n){var r=u(t.dispatches);try{"function"==typeof e?e((function(){w(r,n.value)})):w(r,n.value)}catch(e){throw t.dispatching=void 0,e}}else t.dispatching=void 0};t.dispatching;)o()}}function E(t,e,r){var o,c,i=(o={data:[],current:0,initialized:!1,working:!1},{context:{ref:c=function(t){var e=o.data,n=o.initialized;if(!o.working)throw new Error("Context hook only can be used in model refreshing time.");var r=o.current,c=e[r];if(o.current+=1,c)return c;if(n)throw new Error("Context hook should be used everytime, when model is refreshing.");var u={current:t};return e[r]=u,u},memo:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=c(void 0),o=function(){if(null==r.current)return[t(),e];var o=n(r.current,2),c=o[0];return y(o[1],e)?[c,void 0]:[t(),e]}(),u=n(o,2),i=u[0],a=u[1];return a&&(r.current=[i,a]),i}},reset:function(){o.working=!1,o.current=0,o.initialized=!1,o.data=[]},start:function(){o.working=!0,o.current=0},end:function(){o.working=!1,o.initialized=!0}}),a=P(t,e,i),f=r||{},s=f.controlled,l=f.batchUpdate,p={current:a,reducer:t,dispatch:null,dispatches:[],cacheMethods:{},state:e,cacheState:null,controlled:!!s,notify:g};function v(t,e){var n=p.state,r=!(!e||!e.isDefault),o=!(!e||!e.ignoreDispatch);if(!r||!p.cacheState){var c=e?e.state:n;p.reducer=t,p.state=c,p.cacheState=e&&e.cache?{state:e.state}:p.cacheState,p.current=P(t,p.state,i),n===p.state||r||o||p.notify({state:p.state,type:""})}}function h(t){var e=p.dispatches,n=p.controlled,r=u(e);return!(r.indexOf(t)>=0)&&(n?(p.dispatches=[t],!1):(p.dispatches=r.concat(t),!0))}function b(t){t({state:p.state,type:""})}function O(t){if(t){var e=u(p.dispatches);p.dispatches=e.filter((function(e){return e!==t}))}else p.dispatches=[]}p.notify=k(p,l);var j=d(a,{get:function(t,e){var n=p.current[e];return Object.prototype.hasOwnProperty.call(p.current,e)&&"function"==typeof n?function(t,e,n){if(t.cacheMethods[e])return t.cacheMethods[e];var r=function(){for(var r=arguments.length,o=new Array(r),c=0;c<r;c++)o[c]=arguments[c];var u=t.current[e].apply(void 0,o),i=t.reducer,a=t.controlled,f={type:e,state:u};return a?(t.notify(f),u):(t.current=P(i,u,n),t.state=u,t.cacheState={state:u},t.notify({type:e,state:u}),u)};return t.cacheMethods[e]=r,r}(p,e,i):n}});return{agent:j,getCacheState:function(){return p.cacheState},getState:function(){return p.state},getCurrent:function(){if(Array.isArray(p.current))return p.current.map((function(t,e){return"function"==typeof t?j[e]:t}));var t=Object.keys(p.current),e=m({},p.current);return t.forEach((function(t){"function"==typeof e[t]&&(e[t]=j[t])})),e},getListeners:function(){return p.dispatches},update:v,updateState:function(t){v(p.reducer,{state:t,cache:!0})},notice:function(){b(p.notify)},tunnel:function(t){return{connect:function(){h(t)&&b(t)},disconnect:function(){O(t)}}},connect:function(t){h(t)&&b(t)},disconnect:O}}function x(t){if(t.agent[j])throw new Error("A stateless connection should be initialized before it is accessed.")}function C(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if("function"==typeof t&&"function"==typeof t.creation)return[{key:n.join("."),keys:n,factory:t,connection:t.creation(e)}];if(!t||"object"!==f(t))return[];var r=[],o=t;return Object.keys(o).forEach((function(t){var c=C(o[t],e,n.concat(t));r.push.apply(r,u(c))})),r}function M(t,e){var n=t;function r(t){var e=t.map((function(t){return t.connection})),n=function(t){return{get:function(e){var n=t.find((function(t){return t.factory===e||t.sourceFactory===e}));return n?n.connection:void 0}}}(t);return{collections:t,connections:e,instances:n}}var o=C(t,e),c=r(o),i={update:function(n){if(n===t)return m({},i);var a=C(n,e),f=r(function(t,e){var n=h(e.map((function(t){return[t.key,{connection:t.connection,factory:t.factory}]}))),r=h(t.map((function(t){return[t.key,{connection:t.connection,factory:t.factory}]}))),o=e.filter((function(t){var e=t.key;return!r.get(e)})),c=t.filter((function(t){var e=t.key;return!n.get(e)})),i=t.map((function(t){var e=t.key,r=t.connection,o=n.get(e);if(o){var c=o.connection,u=null==r.getCacheState()?c.getState():r.getState();return r.update(o.factory,{state:u}),m(m({},t),{},{factory:o.factory,sourceFactory:t.factory})}})).filter((function(t){return!!t}));return c.forEach((function(t){return t.connection.disconnect()})),[].concat(u(o),u(i))}(o,a)),s=f.instances,l=f.connections,p=f.collections;return c.instances=s,c.connections=l,c.collections=p,m({},i)},get:function(t){return c.instances.get(t)},equal:function(t){return t===n},destroy:function(){c.connections.forEach((function(t){return t.disconnect()}))}};return m({},i)}function D(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 A(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?D(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):D(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var I="@@_airmaReactStateRealtimeInstancePropertyV18_@@",q=(0,i.createContext)(void 0);function F(t,e,n,r){var o=(r||{}).disabled,c=(0,i.useRef)(t),u=(0,i.useMemo)((function(){return E(t,e,{controlled:!0})}),[]);o||e===u.getState()&&t===c.current||(u.update(t,{state:e,ignoreDispatch:!0}),c.current=t);var f=(0,a.usePersistFn)((function(t){var r=t.state;e!==r&&(o||n(r))}));return u.connect(f),(0,i.useEffect)((function(){return u.connect(f),function(){u.disconnect(f)}}),[]),d(u.getCurrent(),{get:function(t,e,n){var r=t[e];return e===I?u.agent:r}})}function R(t,e,n){return F(t,e,n)}function z(t,e){var n=Array.isArray(e),r=n?e:e?e.refreshDeps:void 0,o=n?e:e&&e.variables||[],c=(0,a.usePersistFn)(t);(0,i.useEffect)((function(){var t=c.apply(void 0,u(o));return"function"==typeof t?t:function(){}}),r)}var T=(0,i.createContext)(null),U=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=((0,i.useContext)(q)||{}).batchUpdate,u=(0,i.useContext)(T),a=(0,i.useMemo)((function(){return M(o,{batchUpdate:c})}),[]),f=(0,i.useMemo)((function(){return A(A({},a.update(o)),{},{parent:u})}),[u,o]);return(0,i.createElement)(T.Provider,{value:f},r)},_=U,L=U;function G(t,e){if(e.connection)return e.connection;if(null!=t){var n=t.get(e);return!n&&t.parent?G(t.parent,e):n}}function K(t,e,r){var o=t.getSourceFrom,c="function"==typeof o?o():void 0,u=function(t,e,r){var o=A(A({},{refresh:!1,required:!1,autoLink:!1,realtimeInstance:!1}),r),c=o.refresh,u=o.required,f=o.autoLink,s=o.useDefaultState,l=o.realtimeInstance,p=(0,i.useContext)(T),v=u?G(p,t):void 0;if(u&&!f&&!v)throw new Error("The model in usage is a `store key`, it should match with a store created by `StoreProvider`.");var y=null!=v&&!!s&&null==v.getCacheState();y&&v.update(t,{state:e,cache:!0,ignoreDispatch:!0}),null!=v&&x(v);var h=(0,i.useRef)(t),g=(0,i.useRef)((0,i.useMemo)((function(){return v||E(t,e)}),[])).current,b=v||g;h.current===t||v||(h.current=t,b.update(t));var m=n((0,i.useState)(b.getCurrent()),2),O=m[0],j=m[1],w=(0,a.usePersistFn)((function(){j(b.getCurrent())})),S=(0,i.useRef)({state:e});(0,i.useEffect)((function(){var n=S.current;S.current={state:e},c&&n.state!==e&&b.update(t,{state:e,cache:!0})}),[e]);var P=b.tunnel(w);if((0,i.useEffect)((function(){return P.connect(),function(){P.disconnect()}}),[]),(0,i.useEffect)((function(){y&&b.notice()}),[y]),l)return[b.getState(),b.agent,b.updateState];var k=d(O,{get:function(t,e,n){var r=t[e];return e===I?b.agent:r}});return[b.getState(),k,b.updateState]}(c||t,e,r),f=n(u,3),s=f[0],l=f[1],p=F(t,s,f[2],{disabled:!c});return[s,c?p:l]}function V(t,e,r){var o=t.pipe,c=t.getSourceFrom;return n(K(t,e,A({required:"function"==typeof o||"function"==typeof c,useDefaultState:arguments.length>1},r)),2)[1]}function Y(t,e,n){return V(t,e,A(A({},n),{},{refresh:!0}))}var $=function(t){return'API "'.concat(t,'" can not work, there is no matched StoreProvider with its store key.')};function B(t,e,r){var o=G((0,i.useContext)(T),t);if(!o)throw new Error($("useSelector"));x(o);var c=e(o.getCurrent()),u=n((0,i.useState)({data:c}),2),f=u[0],s=u[1],l=(0,a.usePersistFn)((function(){var t=e(o.getCurrent());(function(t,e){return r?r(t,e):Object.is(t,e)})(f.data,t)||s({data:t})})),p=o.tunnel(l);return(0,i.useEffect)((function(){return p.connect(),function(){p.disconnect()}}),[]),f.data}function H(t){return function(e){return function(n){return(0,i.createElement)(U,{value:t},(0,i.createElement)(e,n))}}}function J(t){var e=t[I];return e||t}function N(t){var e=t.pipe,n=(0,i.useContext)(T);return"function"==typeof e&&null!=(n?G(n,t):null)}var Q=y,W=function(t,e){return function(t,e,n){var o=function(e){return t(e)};return o.creation=function(t){return n?E((function(t){return r({},j,O)}),void 0,t):E(o,e,t)},o.pipe=function(t){var e=function(e){return t(e)};return e.getSourceFrom=function(){return o},e},o.global=function(){return function(t){var e=function(e){return t(e)};return e.effect=t.effect,e.connection=t.creation(),e.pipe=t.pipe,e.global=function(){return e},e}(o)},o}(t,e,arguments.length<2)},X=function(t){var e=t.value,n=t.children;return(0,i.createElement)(q.Provider,{value:e},n)},Z=function(t){var e=function e(n,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],c=null!=r?r:arguments.length>0?W(t,n):W(t);var a={key:c,keys:o,useModel:function(t){var e=arguments.length?[c,t]:[c];return V.apply(void 0,e)},useSelector:function(t,e){return B(c,t,e)},asGlobal:function(){var t=c.global();return{useModel:function(e){var n=arguments.length?[t,e]:[t];return V.apply(void 0,n)},useSelector:function(e,n){return B(t,e,n)}}},provide:function(){return H([c].concat(u(o)))},provideTo:function(t){return H([c].concat(u(o)))(t)},Provider:function(t){var e=t.children;return(0,i.createElement)(U,{value:[c].concat(u(o))},e)}};return A(A({},a),{},{with:function(){for(var t=arguments.length,r=new Array(t),u=0;u<t;u++)r[u]=arguments[u];var i=o.concat(r.map((function(t){return"function"==typeof t?t:t.key})));return e(n,c,i)}})};function n(t){return arguments.length?e(t):e()}return Object.assign(t,{useModel:function(e){var n=arguments.length?[t,e]:[t];return V.apply(void 0,n)},useControlledModel:function(e,n){return R(t,e,n)},store:n,createStore:n})};Z.context=function(){var t=S.context;if(null==t)throw new Error("Can not use context out of the model refresh time.");return t},Z.create=Z}(),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(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.")}()}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(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.")}()}o.r(c),o.d(c,{ConfigProvider:function(){return X},ModelProvider:function(){return L},Provider:function(){return U},StoreProvider:function(){return _},createKey:function(){return W},model:function(){return Z},provide:function(){return H},shallowEqual:function(){return Q},useControlledModel:function(){return F},useIsModelMatchedInStore:function(){return N},useModel:function(){return V},useRealtimeInstance:function(){return J},useRefresh:function(){return z},useRefreshModel:function(){return Y},useSelector:function(){return B}});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 y(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 h(t){var e={};return t.forEach((function(t){var r=n(t,2),o=r[0],c=r[1];e[o]=c})),{get:function(t){return e[t]}}}function g(){}function b(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 m(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?b(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):b(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var O={},j="@@lazyIdentify";function S(t,e){t.forEach((function(t){t(e)}))}var w={context:null};function P(t,e,n){n.start(),w.context=n.context;var r=t(e);return w.context=null,n.end(),r[j]===O&&n.reset(),r}function k(t,e){return function(n){var r=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}}(n),!r)for(var o=function(){var n=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;return o.tail=r,t.dispatching=o,e}}();if(n){var r=u(t.dispatches);try{"function"==typeof e?e((function(){S(r,n.value)})):S(r,n.value)}catch(e){throw t.dispatching=void 0,e}}else t.dispatching=void 0};t.dispatching;)o()}}function x(t,e,r){var o,c,i=(o={data:[],current:0,initialized:!1,working:!1},{context:{ref:c=function(t){var e=o.data,n=o.initialized;if(!o.working)throw new Error("Context hook only can be used in model refreshing time.");var r=o.current,c=e[r];if(o.current+=1,c)return c;if(n)throw new Error("Context hook should be used everytime, when model is refreshing.");var u={current:t};return e[r]=u,u},memo:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=c(void 0),o=function(){if(null==r.current)return[t(),e];var o=n(r.current,2),c=o[0];return y(o[1],e)?[c,void 0]:[t(),e]}(),u=n(o,2),i=u[0],a=u[1];return a&&(r.current=[i,a]),i}},reset:function(){o.working=!1,o.current=0,o.initialized=!1,o.data=[]},start:function(){o.working=!0,o.current=0},end:function(){o.working=!1,o.initialized=!0}}),a=P(t,e,i),f=r||{},s=f.controlled,l=f.batchUpdate,d={current:a,reducer:t,dispatch:null,dispatches:[],cacheMethods:{},state:e,cacheState:null,controlled:!!s,notify:g};function v(t,e){var n=d.state,r=!(!e||!e.isDefault),o=!(!e||!e.ignoreDispatch);if(!r||!d.cacheState){var c=e?e.state:n;d.reducer=t,d.state=c,d.cacheState=e&&e.cache?{state:e.state}:d.cacheState,d.current=P(t,d.state,i),n===d.state||r||o||d.notify({state:d.state,type:""})}}function h(t){var e=d.dispatches,n=d.controlled,r=u(e);return!(r.indexOf(t)>=0)&&(n?(d.dispatches=[t],!1):(d.dispatches=r.concat(t),!0))}function b(t){t({state:d.state,type:""})}function O(t){if(t){var e=u(d.dispatches);d.dispatches=e.filter((function(e){return e!==t}))}else d.dispatches=[]}d.notify=k(d,l);var j=p(a,{get:function(t,e){var n=d.current[e];return Object.prototype.hasOwnProperty.call(d.current,e)&&"function"==typeof n?function(t,e,n){if(t.cacheMethods[e])return t.cacheMethods[e];var r=function(){for(var r=arguments.length,o=new Array(r),c=0;c<r;c++)o[c]=arguments[c];var u=t.current[e].apply(void 0,o),i=t.reducer,a=t.controlled,f={type:e,state:u};return a?(t.notify(f),u):(t.current=P(i,u,n),t.state=u,t.cacheState={state:u},t.notify({type:e,state:u}),u)};return t.cacheMethods[e]=r,r}(d,e,i):n}});return{agent:j,getCacheState:function(){return d.cacheState},getState:function(){return d.state},getCurrent:function(){if(Array.isArray(d.current))return d.current.map((function(t,e){return"function"==typeof t?j[e]:t}));var t=Object.keys(d.current),e=m({},d.current);return t.forEach((function(t){"function"==typeof e[t]&&(e[t]=j[t])})),e},getListeners:function(){return d.dispatches},update:v,updateState:function(t){v(d.reducer,{state:t,cache:!0})},notice:function(){b(d.notify)},tunnel:function(t){return{connect:function(){h(t)&&b(t)},disconnect:function(){O(t)}}},destroy:function(){d.dispatch=null,d.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}}(d),d.state=e,d.cacheState=null,d.notify=g,d.cacheMethods={}},connect:function(t){h(t)&&b(t)},disconnect:O}}function E(t){if(t.agent[j])throw new Error("A stateless connection should be initialized before it is accessed.")}function C(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];if("function"==typeof t&&"function"==typeof t.creation)return[{key:n.join("."),keys:n,factory:t,connection:t.creation(e)}];if(!t||"object"!==f(t))return[];var r=[],o=t;return Object.keys(o).forEach((function(t){var c=C(o[t],e,n.concat(t));r.push.apply(r,u(c))})),r}function M(t,e){var n=t;function r(t){var e=t.map((function(t){return t.connection})),n=function(t){return{get:function(e){var n=t.find((function(t){return t.factory===e||t.sourceFactory===e}));return n?n.connection:void 0}}}(t);return{collections:t,connections:e,instances:n}}var o=C(t,e),c=r(o),i={update:function(n){if(n===t)return m({},i);var a=C(n,e),f=r(function(t,e){var n=h(e.map((function(t){return[t.key,{connection:t.connection,factory:t.factory}]}))),r=h(t.map((function(t){return[t.key,{connection:t.connection,factory:t.factory}]}))),o=e.filter((function(t){var e=t.key;return!r.get(e)})),c=t.filter((function(t){var e=t.key;return!n.get(e)})),i=t.map((function(t){var e=t.key,r=t.connection,o=n.get(e);if(o){var c=o.connection,u=null==r.getCacheState()?c.getState():r.getState();return r.update(o.factory,{state:u}),m(m({},t),{},{factory:o.factory,sourceFactory:t.factory})}})).filter((function(t){return!!t}));return c.forEach((function(t){return t.connection.destroy()})),[].concat(u(o),u(i))}(o,a)),s=f.instances,l=f.connections,d=f.collections;return c.instances=s,c.connections=l,c.collections=d,m({},i)},get:function(t){return c.instances.get(t)},equal:function(t){return t===n},destroy:function(){c.connections.forEach((function(t){return t.destroy()}))}};return m({},i)}function D(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 A(t){for(var e=1;e<arguments.length;e++){var n=null!=arguments[e]?arguments[e]:{};e%2?D(Object(n),!0).forEach((function(e){r(t,e,n[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(n)):D(Object(n)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(n,e))}))}return t}var I="@@_airmaReactStateRealtimeInstancePropertyV18_@@",R=(0,i.createContext)(void 0);function q(t,e,n,r){var o=(r||{}).disabled,c=(0,i.useRef)(t),u=(0,i.useMemo)((function(){return x(t,e,{controlled:!0})}),[]);o||e===u.getState()&&t===c.current||(u.update(t,{state:e,ignoreDispatch:!0}),c.current=t);var f=(0,a.usePersistFn)((function(t){var r=t.state;e!==r&&(o||n(r))}));return u.connect(f),(0,i.useEffect)((function(){return u.connect(f),function(){u.disconnect(f),u.destroy()}}),[]),p(u.getCurrent(),{get:function(t,e,n){var r=t[e];return e===I?u.agent:r}})}function F(t,e,n){return q(t,e,n)}function z(t,e){var n=Array.isArray(e),r=n?e:e?e.refreshDeps:void 0,o=n?e:e&&e.variables||[],c=(0,a.usePersistFn)(t);(0,i.useEffect)((function(){var t=c.apply(void 0,u(o));return"function"==typeof t?t:function(){}}),r)}var T=(0,i.createContext)(null),U=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=((0,i.useContext)(R)||{}).batchUpdate,u=(0,i.useContext)(T),a=(0,i.useMemo)((function(){return M(o,{batchUpdate:c})}),[]),f=(0,i.useMemo)((function(){return A(A({},a.update(o)),{},{parent:u})}),[u,o]);return(0,i.useEffect)((function(){return function(){f.destroy()}}),[]),(0,i.createElement)(T.Provider,{value:f},r)},_=U,L=U;function G(t,e){if(e.connection)return e.connection;if(null!=t){var n=t.get(e);return!n&&t.parent?G(t.parent,e):n}}function K(t,e,r){var o=t.getSourceFrom,c="function"==typeof o?o():void 0,u=function(t,e,r){var o=A(A({},{refresh:!1,required:!1,autoLink:!1,realtimeInstance:!1}),r),c=o.refresh,u=o.required,f=o.autoLink,s=o.useDefaultState,l=o.realtimeInstance,d=(0,i.useRef)(!1),v=(0,i.useContext)(T),y=u?G(v,t):void 0;if(u&&!f&&!y)throw new Error("The model in usage is a `store key`, it should match with a store created by `StoreProvider`.");var h=null!=y&&!!s&&null==y.getCacheState();h&&y.update(t,{state:e,cache:!0,ignoreDispatch:!0}),null!=y&&E(y);var g=(0,i.useRef)(t),b=(0,i.useRef)((0,i.useMemo)((function(){return y||x(t,e)}),[])).current,m=y||b;g.current===t||y||(g.current=t,m.update(t));var O=n((0,i.useState)(m.getCurrent()),2),j=O[0],S=O[1],w=(0,a.usePersistFn)((function(){d.current||S(m.getCurrent())})),P=(0,i.useRef)({state:e});(0,i.useEffect)((function(){var n=P.current;P.current={state:e},c&&n.state!==e&&m.update(t,{state:e,cache:!0})}),[e]);var k=m.tunnel(w);if((0,i.useEffect)((function(){return k.connect(),function(){d.current=!0,k.disconnect(),null==y&&m.destroy()}}),[]),(0,i.useEffect)((function(){h&&m.notice()}),[h]),l)return[m.getState(),m.agent,m.updateState];var C=p(j,{get:function(t,e,n){var r=t[e];return e===I?m.agent:r}});return[m.getState(),C,m.updateState]}(c||t,e,r),f=n(u,3),s=f[0],l=f[1],d=q(t,s,f[2],{disabled:!c});return[s,c?d:l]}function V(t,e,r){var o=t.pipe,c=t.getSourceFrom;return n(K(t,e,A({required:"function"==typeof o||"function"==typeof c,useDefaultState:arguments.length>1},r)),2)[1]}function Y(t,e,n){return V(t,e,A(A({},n),{},{refresh:!0}))}var $=function(t){return'API "'.concat(t,'" can not work, there is no matched StoreProvider with its store key.')};function B(t,e,r){var o=G((0,i.useContext)(T),t);if(!o)throw new Error($("useSelector"));E(o);var c=e(o.getCurrent()),u=(0,i.useRef)(!1),f=n((0,i.useState)({data:c}),2),s=f[0],l=f[1],d=(0,a.usePersistFn)((function(){if(!u.current){var t=e(o.getCurrent());(function(t,e){return r?r(t,e):Object.is(t,e)})(s.data,t)||l({data:t})}})),p=o.tunnel(d);return(0,i.useEffect)((function(){return p.connect(),function(){u.current=!0,p.disconnect()}}),[]),s.data}function H(t){return function(e){return function(n){return(0,i.createElement)(U,{value:t},(0,i.createElement)(e,n))}}}function J(t){var e=t[I];return e||t}function N(t){var e=t.pipe,n=(0,i.useContext)(T);return"function"==typeof e&&null!=(n?G(n,t):null)}var Q=y,W=function(t,e){return function(t,e,n){var o=function(e){return t(e)};return o.creation=function(t){return n?x((function(t){return r({},j,O)}),void 0,t):x(o,e,t)},o.pipe=function(t){var e=function(e){return t(e)};return e.getSourceFrom=function(){return o},e},o.global=function(){return function(t){var e=function(e){return t(e)};return e.effect=t.effect,e.connection=t.creation(),e.pipe=t.pipe,e.global=function(){return e},e}(o)},o}(t,e,arguments.length<2)},X=function(t){var e=t.value,n=t.children;return(0,i.createElement)(R.Provider,{value:e},n)},Z=function(t){var e=function e(n,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[],c=null!=r?r:arguments.length>0?W(t,n):W(t);var a={key:c,keys:o,useModel:function(t){var e=arguments.length?[c,t]:[c];return V.apply(void 0,e)},useSelector:function(t,e){return B(c,t,e)},asGlobal:function(){var t=c.global();return{useModel:function(e){var n=arguments.length?[t,e]:[t];return V.apply(void 0,n)},useSelector:function(e,n){return B(t,e,n)}}},provide:function(){return H([c].concat(u(o)))},provideTo:function(t){return H([c].concat(u(o)))(t)},Provider:function(t){var e=t.children;return(0,i.createElement)(U,{value:[c].concat(u(o))},e)}};return A(A({},a),{},{with:function(){for(var t=arguments.length,r=new Array(t),u=0;u<t;u++)r[u]=arguments[u];var i=o.concat(r.map((function(t){return"function"==typeof t?t:t.key})));return e(n,c,i)}})};function n(t){return arguments.length?e(t):e()}return Object.assign(t,{useModel:function(e){var n=arguments.length?[t,e]:[t];return V.apply(void 0,n)},useControlledModel:function(e,n){return F(t,e,n)},store:n,createStore:n})};Z.context=function(){var t=w.context;if(null==t)throw new Error("Can not use context out of the model refresh time.");return t},Z.create=Z}(),c}()}));
{
"name": "@airma/react-state",
"version": "18.3.0-alpha.12",
"version": "18.3.0",
"description": "the purpose of this project is make useReducer more simplify",

@@ -27,3 +27,3 @@ "license": "MIT",

"dependencies": {
"@airma/react-hooks-core": "^18.3.0-alpha.12",
"@airma/react-hooks-core": "^18.3.0",
"react": ">=16.8.0"

@@ -30,0 +30,0 @@ },

@@ -16,2 +16,9 @@ [![npm][npm-image]][npm-url]

## Documents
* [En](https://filefoxper.github.io/airma/#/react-state/index)
* [中文](https://filefoxper.github.io/airma/#/zh/react-state/index)
## Code first
Create `reducer-like` function:

@@ -53,9 +60,4 @@

## Documents
### Local state management
* [En](https://filefoxper.github.io/airma/#/react-state/index)
* [中文](https://filefoxper.github.io/airma/#/zh/react-state/index)
## Local state management
```tsx

@@ -86,3 +88,3 @@ import {model} from '@airma/react-state';

## React.Context state management
### React.Context state management

@@ -136,3 +138,3 @@ ```tsx

## Global state management
### Global state management

@@ -139,0 +141,0 @@ ```ts