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
96
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 18.3.1 to 18.3.2

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 Z},ModelProvider:function(){return L},Provider:function(){return U},StoreProvider:function(){return _},createKey:function(){return X},model:function(){return tt},provide:function(){return J},shallowEqual:function(){return W},useControlledModel:function(){return F},useIsModelMatchedInStore:function(){return Q},useModel:function(){return V},useRealtimeInstance:function(){return N},useRefresh:function(){return z},useRefreshModel:function(){return $},useSelector:function(){return H},useStaticModel: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 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={},S="@@lazyIdentify";function j(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[S]===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(){j(r,n.value)})):j(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 S=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:S,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?S[e]:t}));var t=Object.keys(d.current),e=m({},d.current);return t.forEach((function(t){"function"==typeof e[t]&&(e[t]=S[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[S])throw new Error("A stateless connection should be initialized before it is accessed.")}function M(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=M(o[t],e,n.concat(t));r.push.apply(r,u(c))})),r}function C(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=M(t,e),c=r(o),i={update:function(n){if(n===t)return m({},i);var a=M(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 C(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=o.updateDeps,v=(0,i.useRef)(!1),h=(0,i.useContext)(T),g=u?G(h,t):void 0;if(u&&!f&&!g)throw new Error("The model in usage is a `store key`, it should match with a store created by `StoreProvider`.");var b=null!=g&&!!s&&null==g.getCacheState();b&&g.update(t,{state:e,cache:!0,ignoreDispatch:!0}),null!=g&&E(g);var m=(0,i.useRef)(t),O=(0,i.useRef)((0,i.useMemo)((function(){return g||x(t,e)}),[])).current,S=g||O;m.current===t||g||(m.current=t,S.update(t));var j=n((0,i.useState)(S.getCurrent()),2),w=j[0],P=j[1],k=(0,i.useRef)(d?d(w):void 0),M=(0,a.usePersistFn)((function(){if(!v.current){var t=S.getCurrent(),e=d?d(t):void 0;k.current&&e&&y(k.current,e)||P(t)}})),C=(0,i.useRef)({state:e});(0,i.useEffect)((function(){var n=C.current;C.current={state:e},c&&n.state!==e&&S.update(t,{state:e,cache:!0})}),[e]);var D=S.tunnel(M);if((0,i.useEffect)((function(){return D.connect(),function(){v.current=!0,D.disconnect(),null==g&&S.destroy()}}),[]),(0,i.useEffect)((function(){b&&S.notice()}),[b]),l)return[S.getState(),S.agent,S.updateState];var R=p(w,{get:function(t,e,n){var r=t[e];return e===I?S.agent:r}});return[S.getState(),R,S.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,r){var o=t.pipe,c=t.getSourceFrom;return n(K(t,e,A(A({required:"function"==typeof o||"function"==typeof c,useDefaultState:arguments.length>1},r),{},{updateDeps:function(){return[]}})),2)[1]}function $(t,e,n){return V(t,e,A(A({},n),{},{refresh:!0}))}var B=function(t){return'API "'.concat(t,'" can not work, there is no matched StoreProvider with its store key.')};function H(t,e,r){var o=G((0,i.useContext)(T),t);if(!o)throw new Error(B("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 J(t){return function(e){return function(n){return(0,i.createElement)(U,{value:t},(0,i.createElement)(e,n))}}}function N(t){var e=t[I];return e||t}function Q(t){var e=t.pipe,n=(0,i.useContext)(T);return"function"==typeof e&&null!=(n?G(n,t):null)}var W=y,X=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({},S,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)},Z=function(t){var e=t.value,n=t.children;return(0,i.createElement)(R.Provider,{value:e},n)},tt=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?X(t,n):X(t);var a={key:c,keys:o,useModel:function(t){var e=arguments.length?[c,t]:[c];return V.apply(void 0,e)},useStaticModel:function(t){var e=arguments.length?[c,t]:[c];return Y.apply(void 0,e)},useSelector:function(t,e){return H(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)},useStaticModel:function(e){var n=arguments.length?[t,e]:[t];return Y.apply(void 0,n)},useSelector:function(e,n){return H(t,e,n)}}},provide:function(){return J([c].concat(u(o)))},provideTo:function(t){return J([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})};tt.context=function(){var t=w.context;if(null==t)throw new Error("Can not use context out of the model refresh time.");return t},tt.create=tt}(),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 tt},ModelProvider:function(){return G},Provider:function(){return _},StoreProvider:function(){return L},createKey:function(){return Z},model:function(){return et},provide:function(){return N},shallowEqual:function(){return X},useControlledModel:function(){return q},useIsModelMatchedInStore:function(){return W},useModel:function(){return Y},useRealtimeInstance:function(){return Q},useRefresh:function(){return F},useRefreshModel:function(){return B},useSelector:function(){return J},useStaticModel:function(){return $}});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 b(){}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 m(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 O={},S="@@lazyIdentify";function j(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[S]===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.batchUpdate?e.batchUpdate((function(){j(r,n.value)})):j(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={batchUpdate:f.batchUpdate},p={current:a,reducer:t,dispatch:null,dispatches:[],cacheMethods:{},state:e,cacheState:null,controlled:!!s,notify:b};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 g(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 S=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:S,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?S[e]:t}));var t=Object.keys(p.current),e=m({},p.current);return t.forEach((function(t){"function"==typeof e[t]&&(e[t]=S[t])})),e},getListeners:function(){return p.dispatches},update:v,updateState:function(t){v(p.reducer,{state:t,cache:!0})},notice:function(){g(p.notify)},tunnel:function(t){return{connect:function(){h(t)&&g(t)},disconnect:function(){O(t)}}},destroy:function(){p.dispatch=null,p.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}}(p),p.state=e,p.cacheState=null,p.notify=b,p.cacheMethods={},l.batchUpdate=void 0},connect:function(t){h(t)&&g(t)},disconnect:O,optimize:function(t){l.batchUpdate!==t&&(l.batchUpdate=t)}}}function E(t){if(t.agent[S])throw new Error("A stateless connection should be initialized before it is accessed.")}function M(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=M(o[t],e,n.concat(t));r.push.apply(r,u(c))})),r}function C(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=M(t,e),c=r(o),i={update:function(n){if(n===t)return m({},i);var a=M(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,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.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 U="@@_airmaReactStateRealtimeInstancePropertyV18_@@",I=(0,i.createContext)(void 0);function R(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()}}),[]),d(u.getCurrent(),{get:function(t,e,n){var r=t[e];return e===U?u.agent:r}})}function q(t,e,n){return R(t,e,n)}function F(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 z=(0,i.createContext)(null);function T(){var t=((0,i.useContext)(I)||{}).batchUpdate;return(0,i.useMemo)((function(){return{batchUpdate:t}}),[t])}var _=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=T().batchUpdate,u=(0,i.useContext)(z),a=(0,i.useMemo)((function(){return C(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)(z.Provider,{value:f},r)},L=_,G=_;function K(t,e){if(e.connection)return e.connection;if(null!=t){var n=t.get(e);return!n&&t.parent?K(t.parent,e):n}}function V(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=o.updateDeps,v=T().batchUpdate,h=(0,i.useRef)(!1),b=(0,i.useContext)(z),g=u?K(b,t):void 0;if(u&&!f&&!g)throw new Error("The model in usage is a `store key`, it should match with a store created by `StoreProvider`.");var m=null!=g&&!!s&&null==g.getCacheState();m&&g.update(t,{state:e,cache:!0,ignoreDispatch:!0}),null!=g&&E(g);var O=(0,i.useRef)(t),S=(0,i.useRef)((0,i.useMemo)((function(){return g||x(t,e)}),[])).current;S.optimize(v);var j=g||S;O.current===t||g||(O.current=t,j.update(t));var w=n((0,i.useState)(j.getCurrent()),2),P=w[0],k=w[1],M=(0,i.useRef)(p?p(P):void 0),C=(0,a.usePersistFn)((function(){if(!h.current){var t=j.getCurrent(),e=p?p(t):void 0;M.current&&e&&y(M.current,e)||k(t)}})),D=(0,i.useRef)({state:e});(0,i.useEffect)((function(){var n=D.current;D.current={state:e},c&&n.state!==e&&j.update(t,{state:e,cache:!0})}),[e]);var I=j.tunnel(C);if((0,i.useEffect)((function(){return I.connect(),function(){h.current=!0,I.disconnect(),null==g&&j.destroy()}}),[]),(0,i.useEffect)((function(){m&&j.notice()}),[m]),l)return[j.getState(),j.agent,j.updateState];var R=d(P,{get:function(t,e,n){var r=t[e];return e===U?j.agent:r}});return[j.getState(),R,j.updateState]}(c||t,e,r),f=n(u,3),s=f[0],l=f[1],p=R(t,s,f[2],{disabled:!c});return[s,c?p:l]}function Y(t,e,r){var o=t.pipe,c=t.getSourceFrom;return n(V(t,e,A({required:"function"==typeof o||"function"==typeof c,useDefaultState:arguments.length>1},r)),2)[1]}function $(t,e,r){var o=t.pipe,c=t.getSourceFrom;return n(V(t,e,A(A({required:"function"==typeof o||"function"==typeof c,useDefaultState:arguments.length>1},r),{},{updateDeps:function(){return[]}})),2)[1]}function B(t,e,n){return Y(t,e,A(A({},n),{},{refresh:!0}))}var H=function(t){return'API "'.concat(t,'" can not work, there is no matched StoreProvider with its store key.')};function J(t,e,r){var o=T().batchUpdate,c=K((0,i.useContext)(z),t);if(!c)throw new Error(H("useSelector"));E(c),c.optimize(o);var u=e(c.getCurrent()),f=(0,i.useRef)(!1),s=n((0,i.useState)({data:u}),2),l=s[0],p=s[1],d=(0,a.usePersistFn)((function(){if(!f.current){var t=e(c.getCurrent());(function(t,e){return r?r(t,e):Object.is(t,e)})(l.data,t)||p({data:t})}})),v=c.tunnel(d);return(0,i.useEffect)((function(){return v.connect(),function(){f.current=!0,v.disconnect()}}),[]),l.data}function N(t){return function(e){return function(n){return(0,i.createElement)(_,{value:t},(0,i.createElement)(e,n))}}}function Q(t){var e=t[U];return e||t}function W(t){var e=t.pipe,n=(0,i.useContext)(z);return"function"==typeof e&&null!=(n?K(n,t):null)}var X=y,Z=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({},S,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)},tt=function(t){var e=t.value,n=t.children;return(0,i.createElement)(I.Provider,{value:e},n)},et=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?Z(t,n):Z(t);var a={key:c,keys:o,useModel:function(t){var e=arguments.length?[c,t]:[c];return Y.apply(void 0,e)},useStaticModel:function(t){var e=arguments.length?[c,t]:[c];return $.apply(void 0,e)},useSelector:function(t,e){return J(c,t,e)},asGlobal:function(){var t=c.global();return{useModel:function(e){var n=arguments.length?[t,e]:[t];return Y.apply(void 0,n)},useStaticModel:function(e){var n=arguments.length?[t,e]:[t];return $.apply(void 0,n)},useSelector:function(e,n){return J(t,e,n)}}},provide:function(){return N([c].concat(u(o)))},provideTo:function(t){return N([c].concat(u(o)))(t)},Provider:function(t){var e=t.children;return(0,i.createElement)(_,{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 Y.apply(void 0,n)},useControlledModel:function(e,n){return q(t,e,n)},store:n,createStore:n})};et.context=function(){var t=w.context;if(null==t)throw new Error("Can not use context out of the model refresh time.");return t},et.create=et}(),c}()}));
{
"name": "@airma/react-state",
"version": "18.3.1",
"version": "18.3.2",
"description": "the purpose of this project is make useReducer more simplify",

@@ -5,0 +5,0 @@ "license": "MIT",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc